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 sladjmat
Home > sltoolbox > graph > sladjmat.m

sladjmat

PURPOSE ^

SLADJMAT Constructs the adjacency matrix representation of a graph

SYNOPSIS ^

function A = sladjmat(G, varargin)

DESCRIPTION ^

SLADJMAT Constructs the adjacency matrix representation of a graph

 $ Syntax $
   - A = sladjmat(G, ...)

 $ Arguments $
   - G:        The input graph
   - A:        The adjacency matrix representation of the graph

 $ Description $
   - A = sladjmat(G, ...) constructs the adjacency matrix representation
     of a graph. You can specify the following properties to control
     the construction.
       - 'valtype':        the value type of the target matrix
                           - 'auto': if has value, make numeric matrix
                                     if no value, make logical matrix
                           - 'logical': make logical matrix always
                           - 'numeric': make numeric matrix always
                           (default = 'auto')
       - 'sparse':         whether to create a sparse matrix 
                           (default = true)
       - 'preprune':       whether to prune the edges first 
                           (default = false)
       - 'prunemethod':    the method used to prune the edge set
                           (default = [], means using default method)
                           refer to slpruneedgeset for the specification 
                           of the prune methods.
       - 'sym':            whether to create symmetric graph
       - 'symmethod':      the method to symmetrize the graph
                           (default = [], means using default method)
                           refer to slsymedgeset for the specification.

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

CROSS-REFERENCE INFORMATION ^

This function calls:
  • sladjlist2edgeset SLADJLIST2EDGESET Converts the adjacency list to edge set
  • sledges2adjmat SLEDGES2ADJMAT Creates an adjacency matrix from edge set
  • slgraphinfo SLGRAPHINFO Extracts basic information of a given graph representation
  • slsymgraph SLSYMGRAPH Forces symmetry of the adjacency matrix of a graph
  • slparseprops SLPARSEPROPS Parses input parameters
This function is called by:
  • 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
  • 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

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function A = sladjmat(G, varargin)
0002 %SLADJMAT Constructs the adjacency matrix representation of a graph
0003 %
0004 % $ Syntax $
0005 %   - A = sladjmat(G, ...)
0006 %
0007 % $ Arguments $
0008 %   - G:        The input graph
0009 %   - A:        The adjacency matrix representation of the graph
0010 %
0011 % $ Description $
0012 %   - A = sladjmat(G, ...) constructs the adjacency matrix representation
0013 %     of a graph. You can specify the following properties to control
0014 %     the construction.
0015 %       - 'valtype':        the value type of the target matrix
0016 %                           - 'auto': if has value, make numeric matrix
0017 %                                     if no value, make logical matrix
0018 %                           - 'logical': make logical matrix always
0019 %                           - 'numeric': make numeric matrix always
0020 %                           (default = 'auto')
0021 %       - 'sparse':         whether to create a sparse matrix
0022 %                           (default = true)
0023 %       - 'preprune':       whether to prune the edges first
0024 %                           (default = false)
0025 %       - 'prunemethod':    the method used to prune the edge set
0026 %                           (default = [], means using default method)
0027 %                           refer to slpruneedgeset for the specification
0028 %                           of the prune methods.
0029 %       - 'sym':            whether to create symmetric graph
0030 %       - 'symmethod':      the method to symmetrize the graph
0031 %                           (default = [], means using default method)
0032 %                           refer to slsymedgeset for the specification.
0033 %
0034 % $ History $
0035 %   - Created by Dahua Lin, on Sep 10, 2006
0036 %
0037 
0038 %% parse the graph
0039 
0040 gi = slgraphinfo(G);
0041 
0042 
0043 
0044 %% main skeleton
0045 
0046 switch gi.form
0047     case 'edgeset'
0048         A = sledges2adjmat(gi.n, gi.nt, G.edges, varargin{:});
0049         
0050     case 'adjlist'
0051         if gi.valued
0052             sch = 3;
0053         else
0054             sch = 0;
0055         end
0056         edges = sladjlist2edgeset(G.targets, sch);
0057         A = sledges2adjmat(gi.n, gi.nt, edges, varargin{:});
0058         
0059     case 'adjmat'
0060         opts = struct(...
0061             'valtype', 'auto', ...
0062             'sparse', true, ...
0063             'preprune', false, ...
0064             'prunemethod', [], ...
0065             'sym', false, ...
0066             'symmethod', []);
0067         opts = slparseprops(opts, varargin{:});
0068         A = change_adjmat(G, opts);
0069 end
0070    
0071 
0072 %% auxiliary functions
0073 
0074 function A = change_adjmat(A0, opts)
0075 
0076 switch opts.valtype
0077     case 'auto'
0078         is_logic = islogical(A0);
0079     case 'logical';
0080         is_logic = true;
0081     case 'numeric'
0082         is_logic = false;
0083 end
0084 
0085 if is_logic
0086     if islogical(A0)
0087         A = A0;
0088     else
0089         A = (A0 ~= 0);
0090     end
0091 else
0092     if isa(A0, 'double')
0093         A = A0;
0094     else
0095         A = double(A0);
0096     end
0097 end
0098 
0099 if opts.sparse
0100     if ~issparse(A)
0101         A = sparse(A);
0102     end
0103 else
0104     if issparse(A)
0105         A = full(A);
0106     end
0107 end
0108 
0109 if opts.sym
0110     A = slsymgraph(A, opts.symmethod);
0111 end
0112 
0113 
0114         
0115         
0116     
0117 
0118         
0119 
0120 
0121 
0122 
0123 
0124 
0125

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

Contact us at files@mathworks.com