Files
agent_compositor_test/references/igraph-1.0.1/doc/html/igraph-Embedding.html
T
Abdelrahman Said a11edf0c53 Add graph references
2026-06-28 13:49:01 +01:00

597 lines
22 KiB
HTML
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Chapter 28. Embedding of graphs</title>
<meta name="generator" content="DocBook XSL Stylesheets Vsnapshot">
<link rel="home" href="index.html" title="igraph Reference Manual">
<link rel="up" href="index.html" title="igraph Reference Manual">
<link rel="prev" href="igraph-HRG.html" title="Chapter 27. Hierarchical random graphs">
<link rel="next" href="igraph-Layout.html" title="Chapter 29. Generating layouts for graph drawing">
<script type="text/javascript" src="toggle.js"></script><link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" type="text/css">
<link rel="chapter" href="igraph-Introduction.html" title="Chapter 1. Introduction">
<link rel="chapter" href="igraph-Installation.html" title="Chapter 2. Installation">
<link rel="chapter" href="igraph-Tutorial.html" title="Chapter 3. Tutorial">
<link rel="chapter" href="igraph-Basic.html" title="Chapter 4. Basic data types and interface">
<link rel="chapter" href="igraph-Error.html" title="Chapter 5. Error handling">
<link rel="chapter" href="igraph-Memory.html" title="Chapter 6. Memory (de)allocation">
<link rel="chapter" href="igraph-Data-structures.html" title="Chapter 7. Data structure library: vector, matrix, other data types">
<link rel="chapter" href="igraph-Random.html" title="Chapter 8. Random numbers">
<link rel="chapter" href="igraph-Iterators.html" title="Chapter 9. Vertex and edge selectors and sequences, iterators">
<link rel="chapter" href="igraph-Attributes.html" title="Chapter 10. Graph, vertex and edge attributes">
<link rel="chapter" href="igraph-Generators.html" title="Chapter 11. Deterministic graph generators">
<link rel="chapter" href="igraph-Games.html" title='Chapter 12. Stochastic graph generators ("games")'>
<link rel="chapter" href="igraph-Bipartite.html" title="Chapter 13. Bipartite, i.e. two-mode graphs">
<link rel="chapter" href="igraph-Spatial.html" title="Chapter 14. Spatial graphs">
<link rel="chapter" href="igraph-Operators.html" title="Chapter 15. Graph operators">
<link rel="chapter" href="igraph-Visitors.html" title="Chapter 16. Graph visitors">
<link rel="chapter" href="igraph-Structural.html" title="Chapter 17. Structural properties of graphs">
<link rel="chapter" href="igraph-Cycles.html" title="Chapter 18. Graph cycles">
<link rel="chapter" href="igraph-Cliques.html" title="Chapter 19. Cliques and independent vertex sets">
<link rel="chapter" href="igraph-Motifs.html" title="Chapter 20. Graph motifs, dyad census and triad census">
<link rel="chapter" href="igraph-Isomorphism.html" title="Chapter 21. Graph isomorphism">
<link rel="chapter" href="igraph-Coloring.html" title="Chapter 22. Graph coloring">
<link rel="chapter" href="igraph-Flows.html" title="Chapter 23. Maximum flows, minimum cuts and related measures">
<link rel="chapter" href="igraph-Separators.html" title="Chapter 24. Vertex separators">
<link rel="chapter" href="igraph-Community.html" title="Chapter 25. Detecting community structure">
<link rel="chapter" href="igraph-Graphlets.html" title="Chapter 26. Graphlets">
<link rel="chapter" href="igraph-HRG.html" title="Chapter 27. Hierarchical random graphs">
<link rel="chapter" href="igraph-Embedding.html" title="Chapter 28. Embedding of graphs">
<link rel="chapter" href="igraph-Layout.html" title="Chapter 29. Generating layouts for graph drawing">
<link rel="chapter" href="igraph-Processes.html" title="Chapter 30. Processes on graphs">
<link rel="chapter" href="igraph-Foreign.html" title="Chapter 31. Reading and writing graphs from and to files">
<link rel="chapter" href="igraph-Linalg.html" title="Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs">
<link rel="chapter" href="igraph-Nongraph.html" title="Chapter 33. Non-graph related functions">
<link rel="chapter" href="igraph-Advanced.html" title="Chapter 34. Advanced igraph programming">
<link rel="chapter" href="igraph-Glossary.html" title="Chapter 35. Glossary">
<link rel="chapter" href="igraph-Licenses.html" title="Chapter 36. Licenses for igraph and this manual">
<link rel="index" href="ix01.html" title="Index">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<div class="navigation-header mb-4" width="100%" summary="Navigation header"><div class="btn-group">
<a accesskey="p" class="btn btn-light" href="igraph-HRG.html"><i class="fa fa-chevron-left"></i>
Previous
</a><a accesskey="h" class="btn btn-light" href="index.html"><i class="fa fa-home"></i>
Home
</a><a accesskey="n" class="btn btn-light" href="igraph-Layout.html"><i class="fa fa-chevron-right"></i>
Next
</a>
</div></div>
<div class="chapter">
<div class="titlepage"><div><div><h1 class="title">
<a name="igraph-Embedding"></a>Chapter 28. Embedding of graphs</h1></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="section"><a href="igraph-Embedding.html#spectral-embedding">1. Spectral embedding</a></span></dt></dl></div>
<div class="section">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="spectral-embedding"></a>1. Spectral embedding</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="section"><a href="igraph-Embedding.html#igraph_adjacency_spectral_embedding">1.1. <code class="function">igraph_adjacency_spectral_embedding</code> — Adjacency spectral embedding</a></span></dt>
<dt><span class="section"><a href="igraph-Embedding.html#igraph_laplacian_spectral_embedding">1.2. <code class="function">igraph_laplacian_spectral_embedding</code> — Spectral embedding of the Laplacian of a graph</a></span></dt>
<dt><span class="section"><a href="igraph-Embedding.html#igraph_dim_select">1.3. <code class="function">igraph_dim_select</code> — Dimensionality selection.</a></span></dt>
</dl></div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_adjacency_spectral_embedding"></a>1.1. <code class="function">igraph_adjacency_spectral_embedding</code> — Adjacency spectral embedding</h3></div></div></div>
<a class="indexterm" name="id-1.29.2.2.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_error_t igraph_adjacency_spectral_embedding(const igraph_t *graph,
igraph_int_t n,
const igraph_vector_t *weights,
igraph_eigen_which_position_t which,
igraph_bool_t scaled,
igraph_matrix_t *X,
igraph_matrix_t *Y,
igraph_vector_t *D,
const igraph_vector_t *cvec,
igraph_arpack_options_t *options);
</pre></div>
<p>
</p>
<p>
Spectral decomposition of the adjacency matrices of graphs.
This function computes an <code class="literal">n</code>-dimensional Euclidean
representation of the graph based on its adjacency
matrix, A. This representation is computed via the singular value
decomposition of the adjacency matrix, A=U D V^T. In the case,
where the graph is a random dot product graph generated using latent
position vectors in R^n for each vertex, the embedding will
provide an estimate of these latent vectors.
</p>
<p>
For undirected graphs, the latent positions are calculated as
X = U^n D^(1/2) where U^n equals to the first no columns of U, and
D^(1/2) is a diagonal matrix containing the square root of the selected
singular values on the diagonal.
</p>
<p>
For directed graphs, the embedding is defined as the pair
X = U^n D^(1/2), Y = V^n D^(1/2).
(For undirected graphs U=V, so it is sufficient to keep one of them.)
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
<td><p>
The input graph, can be directed or undirected.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
<td><p>
An integer scalar. This value is the embedding dimension of
the spectral embedding. Should be smaller than the number of
vertices. The largest n-dimensional non-zero
singular values are used for the spectral embedding.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>weights</code></em>:</span></p></td>
<td><p>
Optional edge weights. Supply a null pointer for
unweighted graphs.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>which</code></em>:</span></p></td>
<td>
<p>
Which eigenvalues (or singular values, for directed
graphs) to use, possible values:
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_LM</code></span></p></td>
<td><p>
the ones with the largest magnitude
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_LA</code></span></p></td>
<td><p>
the (algebraic) largest ones
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_SA</code></span></p></td>
<td><p>
the (algebraic) smallest ones.
</p></td>
</tr>
</tbody>
</table></div>
<p>
For directed graphs, <code class="literal">IGRAPH_EIGEN_LM</code> and
<code class="literal">IGRAPH_EIGEN_LA</code> are the same because singular
values are used for the ordering instead of eigenvalues.
</p>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>scaled</code></em>:</span></p></td>
<td><p>
Whether to return X and Y (if <code class="constant">scaled</code> is true), or
U and V.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>X</code></em>:</span></p></td>
<td><p>
Initialized matrix, the estimated latent positions are
stored here.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>Y</code></em>:</span></p></td>
<td><p>
Initialized matrix or a null pointer. If not a null
pointer, then the second half of the latent positions are
stored here. (For undirected graphs, this always equals X.)
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>D</code></em>:</span></p></td>
<td><p>
Initialized vector or a null pointer. If not a null
pointer, then the eigenvalues (for undirected graphs) or the
singular values (for directed graphs) are stored here.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>cvec</code></em>:</span></p></td>
<td><p>
A numeric vector, its length is the number vertices in the
graph. This vector is added to the diagonal of the adjacency
matrix, before performing the SVD.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>options</code></em>:</span></p></td>
<td><p>
Options to ARPACK. See <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a>
for details. Supply <code class="constant">NULL</code> to use the defaults. Note that the
function overwrites the <code class="literal">n</code> (number of vertices),
<code class="literal">nev</code> and <code class="literal">which</code> parameters and it always
starts the calculation from a random start vector.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Error code.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_laplacian_spectral_embedding"></a>1.2. <code class="function">igraph_laplacian_spectral_embedding</code> — Spectral embedding of the Laplacian of a graph</h3></div></div></div>
<a class="indexterm" name="id-1.29.2.3.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_error_t igraph_laplacian_spectral_embedding(const igraph_t *graph,
igraph_int_t n,
const igraph_vector_t *weights,
igraph_eigen_which_position_t which,
igraph_laplacian_spectral_embedding_type_t type,
igraph_bool_t scaled,
igraph_matrix_t *X,
igraph_matrix_t *Y,
igraph_vector_t *D,
igraph_arpack_options_t *options);
</pre></div>
<p>
</p>
<p>
This function essentially does the same as
<a class="link" href="igraph-Embedding.html#igraph_adjacency_spectral_embedding" title="1.1. igraph_adjacency_spectral_embedding — Adjacency spectral embedding"><code class="function">igraph_adjacency_spectral_embedding</code></a>, but works on the Laplacian
of the graph, instead of the adjacency matrix.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>graph</code></em>:</span></p></td>
<td><p>
The input graph.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
<td><p>
The number of eigenvectors (or singular vectors if the graph
is directed) to use for the embedding.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>weights</code></em>:</span></p></td>
<td><p>
Optional edge weights. Supply a null pointer for
unweighted graphs.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>which</code></em>:</span></p></td>
<td>
<p>
Which eigenvalues (or singular values, for directed
graphs) to use, possible values:
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_LM</code></span></p></td>
<td><p>
the ones with the largest magnitude
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_LA</code></span></p></td>
<td><p>
the (algebraic) largest ones
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EIGEN_SA</code></span></p></td>
<td><p>
the (algebraic) smallest ones.
</p></td>
</tr>
</tbody>
</table></div>
<p>
For directed graphs, <code class="literal">IGRAPH_EIGEN_LM</code> and
<code class="literal">IGRAPH_EIGEN_LA</code> are the same because singular
values are used for the ordering instead of eigenvalues.
</p>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>type</code></em>:</span></p></td>
<td>
<p>
The type of the Laplacian to use. Various definitions
exist for the Laplacian of a graph, and one can choose
between them with this argument. Possible values:
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EMBEDDING_D_A</code></span></p></td>
<td><p>
means D - A where D is the
degree matrix and A is the adjacency matrix
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EMBEDDING_DAD</code></span></p></td>
<td><p>
means Di times A times Di,
where Di is the inverse of the square root of the degree matrix;
</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="constant">IGRAPH_EMBEDDING_I_DAD</code></span></p></td>
<td><p>
means I - Di A Di, where I
is the identity matrix.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
</td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>scaled</code></em>:</span></p></td>
<td><p>
Whether to return X and Y (if <code class="constant">scaled</code> is true), or
U and V.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>X</code></em>:</span></p></td>
<td><p>
Initialized matrix, the estimated latent positions are
stored here.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>Y</code></em>:</span></p></td>
<td><p>
Initialized matrix or a null pointer. If not a null
pointer, then the second half of the latent positions are
stored here. (For undirected graphs, this always equals X.)
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>D</code></em>:</span></p></td>
<td><p>
Initialized vector or a null pointer. If not a null
pointer, then the eigenvalues (for undirected graphs) or the
singular values (for directed graphs) are stored here.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>options</code></em>:</span></p></td>
<td><p>
Options to ARPACK. See <a class="link" href="igraph-Linalg.html#igraph_arpack_options_t" title="3.1.1. igraph_arpack_options_t — Options for ARPACK."><code class="function">igraph_arpack_options_t</code></a>
for details. Supply <code class="constant">NULL</code> to use the defaults. Note that the
function overwrites the <code class="literal">n</code> (number of vertices),
<code class="literal">nev</code> and <code class="literal">which</code> parameters and it always
starts the calculation from a random start vector.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Error code.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
<p><b>See also: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
<a class="link" href="igraph-Embedding.html#igraph_adjacency_spectral_embedding" title="1.1. igraph_adjacency_spectral_embedding — Adjacency spectral embedding"><code class="function">igraph_adjacency_spectral_embedding</code></a> to embed the adjacency
matrix.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
<div class="section">
<div class="titlepage"><div><div><h3 class="title">
<a name="igraph_dim_select"></a>1.3. <code class="function">igraph_dim_select</code> — Dimensionality selection.</h3></div></div></div>
<a class="indexterm" name="id-1.29.2.4.2"></a><p>
</p>
<div class="informalexample"><pre class="programlisting">
igraph_error_t igraph_dim_select(const igraph_vector_t *sv, igraph_int_t *dim);
</pre></div>
<p>
</p>
<p>
Dimensionality selection for singular values using
profile likelihood.
</p>
<p>
The input of the function is a numeric vector which contains
the measure of "importance" for each dimension.
</p>
<p>
For spectral embedding, these are the singular values of the adjacency
matrix. The singular values are assumed to be generated from a
Gaussian mixture distribution with two components that have different
means and same variance. The dimensionality d is chosen to
maximize the likelihood when the d largest singular values are
assigned to one component of the mixture and the rest of the singular
values assigned to the other component.
</p>
<p>
This function can also be used for the general separation problem,
where we assume that the left and the right of the vector are coming
from two normal distributions, with different means, and we want
to know their border.
</p>
<p><b>Arguments: </b>
</p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><em class="parameter"><code>sv</code></em>:</span></p></td>
<td><p>
A numeric vector, the ordered singular values.
</p></td>
</tr>
<tr>
<td><p><span class="term"><em class="parameter"><code>dim</code></em>:</span></p></td>
<td><p>
The result is stored here.
</p></td>
</tr>
</tbody>
</table></div>
<p>
</p>
<p><b>Returns: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
Error code.
</p></td>
</tr></tbody>
</table></div>
<p>
Time complexity: O(n), n is the number of values in sv.
</p>
<p><b>See also: </b></p>
<div class="variablelist"><table border="0" class="variablelist">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><em class="parameter"><code></code></em></span></p></td>
<td><p>
<a class="link" href="igraph-Embedding.html#igraph_adjacency_spectral_embedding" title="1.1. igraph_adjacency_spectral_embedding — Adjacency spectral embedding"><code class="function">igraph_adjacency_spectral_embedding()</code></a>.
</p></td>
</tr></tbody>
</table></div>
<p>
</p>
</div>
</div>
</div>
<table class="navigation-footer" width="100%" summary="Navigation footer" cellpadding="2" cellspacing="0"><tr valign="middle">
<td align="left"><a accesskey="p" href="igraph-HRG.html"><b>← Chapter 27. Hierarchical random graphs</b></a></td>
<td align="right"><a accesskey="n" href="igraph-Layout.html"><b>Chapter 29. Generating layouts for graph drawing →</b></a></td>
</tr></table>
</body>
</html>