Code covered by the BSD License  

Highlights from
Statistical Learning Toolbox

from Statistical Learning Toolbox by Dahua Lin
Functions for statistical learning, pattern recognition and computer vision, covering many topics.

Description of slgraphinfo
Home > sltoolbox > graph > slgraphinfo.m

slgraphinfo

PURPOSE ^

SLGRAPHINFO Extracts basic information of a given graph representation

SYNOPSIS ^

function gi = slgraphinfo(G, conds)

DESCRIPTION ^

SLGRAPHINFO Extracts basic information of a given graph representation

 $ Syntax $
   - gi = slgraphinfo(G)
   - gi = slgraphinfo(G, conds)

 $ Arguments $
   - G:        The input graph
   - conds:    The cell array of conditions to be checked
   - gi:       the information of the graph
               a struct with the following fields:
               - type: the type of the graph:
                       - 'ge': a general graph
                       - 'bi': a bigraph
               - form: the form of the graph representation:
                       - 'edgeset': edget set representation
                       - 'adjlist': adjacency list representation
                       - 'adjmat':  adjacency matrix representation
               - n:    the number of (source) nodes
               - nt:   the number of (target) nodes
               - valued: whether the graph has values on edges

 $ Description $
   - gi = slgraphinfo(G) extracts the basic information of the graph
     representation and examines the integrity of it. 

   - gi = slgraphinfo(G, conds) verifies whether the graph conforms
     to special conditions. The acceptable conditions:
       - 'square': a square graph, it can be a general graph or a bigraph
                   with n == nt. All graph that is square can be
                   considered as a general graph
       - 'edgeset': the representation is an edge set
       - 'adjlist': the representation is an adjacency list
       - 'adjmat':  the representation is an adjacency matrix
       - [n]:       the n is equal to specified value
       - [n, nt]:   the n and nt are equal to specified value
       - 'numeric': the value type is numeric (only take effect for adjmat)
       - 'logical': the value type is logical (only take effect for adjmat)

 $ Remarks $
   - For a general graph, n and nt are equal, being the number of nodes.

   - When multiple conditions on representation form are specified, only
     the last one takes effect.

 $ History $
   - Created by Dahua Lin, on Sep 9, 2006

CROSS-REFERENCE INFORMATION ^

This function calls:
This function is called by:
  • sladjlist SLADJLIST Construct the adjacency list representation of a graph
  • sladjmat SLADJMAT Constructs the adjacency matrix representation of a graph
  • sledgeset SLEDGESET Construct the edge set representation of a graph
  • slgembed SLGEMBED Solves the general graph-based embedding
  • sllemap SLLEMAP Solves Laplacian Eigenmap Embedding
  • sllle SLLLE Performs Locally Linear Embedding
  • sllle_wg SLLLE_WG Solves the Locally Linear Embedding from weight graph
  • sllocalcoordalign SLLOCALCOORDALIGN Performs optimal local coordinate alignment
  • sllocaltancoords SLLOCALTANCOORDS Computes the local tangent coordinates
  • sllocaltanspace SLLOCALTANSPACE Solves the local tangent spaces
  • slltsa SLLTSA Performs Local Tangent Space Alignment Learning
  • slnbreconweights SLNBRECONWEIGHTS Solve the optimal reconstruction weights on given neighbors
  • slgbfe SLGBFE Performs Graph-based Feature Extraction Learning
  • sldrawgraph SLDRAWGRAPH Draws a graph

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function gi = slgraphinfo(G, conds)
0002 %SLGRAPHINFO Extracts basic information of a given graph representation
0003 %
0004 % $ Syntax $
0005 %   - gi = slgraphinfo(G)
0006 %   - gi = slgraphinfo(G, conds)
0007 %
0008 % $ Arguments $
0009 %   - G:        The input graph
0010 %   - conds:    The cell array of conditions to be checked
0011 %   - gi:       the information of the graph
0012 %               a struct with the following fields:
0013 %               - type: the type of the graph:
0014 %                       - 'ge': a general graph
0015 %                       - 'bi': a bigraph
0016 %               - form: the form of the graph representation:
0017 %                       - 'edgeset': edget set representation
0018 %                       - 'adjlist': adjacency list representation
0019 %                       - 'adjmat':  adjacency matrix representation
0020 %               - n:    the number of (source) nodes
0021 %               - nt:   the number of (target) nodes
0022 %               - valued: whether the graph has values on edges
0023 %
0024 % $ Description $
0025 %   - gi = slgraphinfo(G) extracts the basic information of the graph
0026 %     representation and examines the integrity of it.
0027 %
0028 %   - gi = slgraphinfo(G, conds) verifies whether the graph conforms
0029 %     to special conditions. The acceptable conditions:
0030 %       - 'square': a square graph, it can be a general graph or a bigraph
0031 %                   with n == nt. All graph that is square can be
0032 %                   considered as a general graph
0033 %       - 'edgeset': the representation is an edge set
0034 %       - 'adjlist': the representation is an adjacency list
0035 %       - 'adjmat':  the representation is an adjacency matrix
0036 %       - [n]:       the n is equal to specified value
0037 %       - [n, nt]:   the n and nt are equal to specified value
0038 %       - 'numeric': the value type is numeric (only take effect for adjmat)
0039 %       - 'logical': the value type is logical (only take effect for adjmat)
0040 %
0041 % $ Remarks $
0042 %   - For a general graph, n and nt are equal, being the number of nodes.
0043 %
0044 %   - When multiple conditions on representation form are specified, only
0045 %     the last one takes effect.
0046 %
0047 % $ History $
0048 %   - Created by Dahua Lin, on Sep 9, 2006
0049 %
0050 
0051 %% parse conditions
0052 
0053 if nargin < 2 || isempty(conds)
0054     cc = {};
0055     fc = [];
0056 else
0057     nconds = length(conds);
0058     tf = false(1, nconds);
0059     pf = 0;
0060     for i = 1 : nconds
0061         curcond = conds{i};
0062         if ischar(curcond)
0063             switch curcond 
0064                 case {'adjmat', 'edgeset', 'adjlist'}
0065                     tf(i) = 1;
0066                     pf = i;
0067             end
0068         end
0069     end
0070     if pf > 0
0071         fc = conds{pf};
0072     else
0073         fc = [];
0074     end
0075     cc = conds(~tf);    
0076 end
0077 
0078 
0079 %% parse representation form and delegate
0080 
0081 if isnumeric(G) || islogical(G)
0082     
0083     if ~isempty(fc)
0084         chk_form('adjmat', fc);
0085     end
0086     gi = ginfo_adjmat(G);
0087     
0088 elseif isstruct(G)
0089     if isfield(G, 'edges') && ~isfield(G, 'targets')
0090         
0091         if ~isempty(fc)
0092             chk_form('edgeset', fc);
0093         end
0094         gi = ginfo_edgeset(G);
0095         
0096     elseif isfield(G, 'targets') && ~isfield(G, 'edges')
0097         
0098         if ~isempty(fc)
0099             chk_form('adjlist', fc);
0100         end
0101         gi = ginfo_adjlist(G);
0102         
0103     else
0104         report_unreg();
0105     end
0106 else
0107     report_unreg();
0108 end
0109 
0110 
0111 %% check conditions
0112 
0113 if ~isempty(cc)
0114     ncc = numel(cc);
0115     for i = 1 : ncc
0116         chk_cond(G, gi, cc{i});
0117     end
0118 end
0119 
0120 
0121 
0122 %% Information function for different forms
0123 
0124 function gi = ginfo_edgeset(G)
0125 
0126 gi.form = 'edgeset';
0127 
0128 if ~isfield(G, 'n') || ~isfield(G, 'edges')
0129     chkerr('The edgeset representation of a graph should have the fields n and edges');
0130 end
0131 
0132 ncols = size(G.edges, 2);
0133 if ~isempty(G.edges) && ncols ~= 2 && ncols ~= 3
0134     chkerr('The non-empty edges should have 2 or 3 columns');
0135 end
0136 
0137 if isfield(G, 'nt')
0138     gi.type = 'bi';
0139     gi.n = G.n;
0140     gi.nt = G.nt;        
0141     
0142 else
0143     gi.type = 'ge';
0144     gi.n = G.n;
0145     gi.nt = G.n;
0146     
0147 end
0148 
0149 gi.valued = (ncols == 3);
0150 
0151 
0152 function gi = ginfo_adjlist(G)
0153 
0154 gi.form = 'adjlist';
0155 
0156 if ~isfield(G, 'n') || ~isfield(G, 'targets')
0157     chkerr('The adjlist representation of a graph should have the fields n and targets');
0158 end
0159 
0160 tars = G.targets;
0161 if ~iscell(tars) 
0162     chkerr('The targets should be a cell array');
0163 end
0164 if ~isequal(size(tars), [1, G.n]) && ~isequal(size(tars), [G.n, 1])
0165     chkerr('The targets should be a cell array of size 1 x n or n x 1');
0166 end        
0167 
0168 if isfield(G, 'nt')
0169     gi.type = 'bi';
0170     gi.n = G.n;
0171     gi.nt = G.nt;        
0172     
0173 else
0174     gi.type = 'ge';
0175     gi.n = G.n;
0176     gi.nt = G.n;
0177     
0178 end
0179 
0180 n = G.n;
0181 gi.valued = false;
0182 for i = 1 : n
0183     if ~isempty(tars{i})
0184         ncols = size(tars{i}, 2);
0185         gi.valued = (ncols > 1);
0186         break;
0187     end
0188 end
0189     
0190 
0191 
0192 function gi = ginfo_adjmat(G)
0193 
0194 gi.form = 'adjmat';
0195 
0196 gi.n = size(G, 1);
0197 gi.nt = size(G, 2);
0198 
0199 if gi.n == gi.nt
0200     gi.type = 'ge';
0201 else
0202     gi.type = 'bi';
0203 end
0204 
0205 gi.valued = isnumeric(G);
0206 
0207 
0208 
0209 %% Condition checking function
0210 
0211 function chk_cond(G, gi, cond)
0212 
0213 if ischar(cond)
0214     switch cond
0215         case 'square'
0216             if gi.n ~= gi.nt
0217                 conderr('The graph is square');
0218             end
0219         case 'logical'
0220             if isnumeric(G)
0221                 conderr('The value type is logical');
0222             end
0223         case 'numeric'
0224             if islogical(G)
0225                 conderr('The value type is numeric');
0226             end
0227         otherwise
0228             error('sltoolbox:invalidarg', ...
0229                 'Unknown condition: %s', cond);
0230     end
0231 else
0232     if isscalar(cond)
0233         if gi.n ~= cond
0234             conderr(sprintf('n = %d', cond));
0235         end
0236     elseif isvector(cond) && length(cond) == 2
0237         if gi.n ~= cond(1) || gi.nt ~= cond(2)
0238             conderr(sprintf('n = %d, nt = %d', ...
0239                 cond(1), cond(2)));
0240         end
0241     else
0242         error('sltoolbox:invalidarg', ...
0243             'Invalid condition is specified');
0244     end
0245 end
0246     
0247 
0248 %% Auxiliary function
0249 
0250 function chk_form(df, cf)
0251 
0252 if ~strcmp(df, cf)
0253     error('sltoolbox:invalidarg', ...
0254         'The given graph is like the form %s, which is not the required form %s', ...
0255         df, cf);
0256 end
0257 
0258 
0259 function report_unreg()
0260 
0261 error('sltoolbox:invalidarg', ...
0262     'The graph form is unrecognizable');
0263 
0264 function chkerr(msg)
0265 
0266 error('sltoolbox:invalidarg', ...
0267     'Invalid graph representation: %s', msg);
0268 
0269 function conderr(msg)
0270 
0271 error('sltoolbox:invalidarg', ...
0272     'The given graph does not meet the requirement: %s', msg);
0273 
0274 
0275 
0276 
0277 
0278 
0279     
0280 
0281 
0282

Generated on Wed 20-Sep-2006 12:43:11 by m2html © 2003

Contact us at files@mathworks.com