1321 lines
53 KiB
HTML
1321 lines
53 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||
<title>Chapter 33. Non-graph related functions</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-Linalg.html" title="Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs">
|
||
<link rel="next" href="igraph-Advanced.html" title="Chapter 34. Advanced igraph programming">
|
||
<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-Linalg.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-Advanced.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-Nongraph"></a>Chapter 33. Non-graph related functions </h1></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph-version-number">1. igraph version number</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#running-mean-of-a-time-series">2. Running mean of a time series</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#random-sampling-from-very-long-sequences">3. Random sampling from very long sequences</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#random-sampling-of-spatial-points">4. Random sampling of spatial points</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#fitting-powerlaw-distributions-to-empirical-data">5. Fitting power-law distributions to empirical data</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#compare-floats-with-tolerance">6. Comparing floats with a tolerance</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="igraph-version-number"></a>1. igraph version number</h2></div></div></div>
|
||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="igraph-Nongraph.html#igraph_version">1.1. <code class="function">igraph_version</code> — The version of the igraph C library.</a></span></dt></dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_version"></a>1.1. <code class="function">igraph_version</code> — The version of the igraph C library.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.2.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
void igraph_version(const char **version_string,
|
||
int *major,
|
||
int *minor,
|
||
int *patch);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</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>version_string</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to a string pointer. If not <code class="constant">NULL</code>, it
|
||
is set to the igraph version string, e.g. "0.10.13", "1.2.0", or
|
||
"0.10.13-14-g997f59ad7". It consists of three dot-separated numerical
|
||
parts and potentially of a dash-separated suffix, used in prerelease
|
||
versions. This string must not be modified or deallocated.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>major</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a <code class="constant">NULL</code> pointer, then it is set to the major
|
||
igraph version. E.g. for version "0.10.13" this is 0.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>minor</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a <code class="constant">NULL</code> pointer, then it is set to the minor
|
||
igraph version. E.g. for version "0.10.13" this is 10.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>patch</code></em>:</span></p></td>
|
||
<td><p>
|
||
If not a <code class="constant">NULL</code> pointer, then it is set to the
|
||
subminor igraph version. E.g. for version "0.10.13" this is 13.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.34.2.2.6.1"></a><p class="title"><b>Example 33.1. File <code class="code">examples/simple/igraph_version.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
<span class="strong"><strong>#include</strong></span> <string.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
char tmp[100];
|
||
<span class="strong"><strong>const</strong></span> char *string;
|
||
int major, minor, subminor;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Nongraph.html#igraph_version" title="1.1. igraph_version — The version of the igraph C library.">igraph_version</a></strong></span>(&string, &major, &minor, &subminor);
|
||
<span class="strong"><strong>snprintf</strong></span>(tmp, <span class="strong"><strong>sizeof</strong></span>(tmp), "%i.%i.%i", major, minor, subminor);
|
||
|
||
<span class="strong"><strong>if</strong></span> (<span class="strong"><strong>strncmp</strong></span>(string, tmp, <span class="strong"><strong>strlen</strong></span>(tmp))) {
|
||
<span class="strong"><strong>return</strong></span> 1;
|
||
}
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="running-mean-of-a-time-series"></a>2. Running mean of a time series</h2></div></div></div>
|
||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="igraph-Nongraph.html#igraph_running_mean">2.1. <code class="function">igraph_running_mean</code> — Calculates the running mean of a vector.</a></span></dt></dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_running_mean"></a>2.1. <code class="function">igraph_running_mean</code> — Calculates the running mean of a vector.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.3.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_running_mean(const igraph_vector_t *data, igraph_vector_t *res,
|
||
igraph_int_t binwidth);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
The running mean is defined by the mean of the
|
||
previous <em class="parameter"><code>binwidth</code></em> values.
|
||
</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>data</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vector containing the data.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
The vector containing the result. This should be
|
||
initialized before calling this function and will be
|
||
resized.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>binwidth</code></em>:</span></p></td>
|
||
<td><p>
|
||
Integer giving the width of the bin for the running
|
||
mean calculation.
|
||
</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 length of
|
||
the data vector.
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="random-sampling-from-very-long-sequences"></a>3. Random sampling from very long sequences</h2></div></div></div>
|
||
<div class="toc"><dl class="toc"><dt><span class="section"><a href="igraph-Nongraph.html#igraph_random_sample">3.1. <code class="function">igraph_random_sample</code> — Generates an increasing random sequence of integers.</a></span></dt></dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_random_sample"></a>3.1. <code class="function">igraph_random_sample</code> — Generates an increasing random sequence of integers.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.4.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_random_sample(igraph_vector_int_t *res, igraph_int_t l, igraph_int_t h,
|
||
igraph_int_t length);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function generates an increasing sequence of random integer
|
||
numbers from a given interval. The algorithm is taken literally
|
||
from (Vitter 1987). This method can be used for generating numbers from a
|
||
<span class="emphasis"><em>very</em></span> large interval. It is primarily created for randomly
|
||
selecting some edges from the sometimes huge set of possible edges
|
||
in a large graph.
|
||
|
||
</p>
|
||
<p>
|
||
Reference:
|
||
|
||
</p>
|
||
<p>
|
||
J. S. Vitter. An efficient algorithm for sequential random sampling.
|
||
ACM Transactions on Mathematical Software, 13(1):58--67, 1987.
|
||
<a class="ulink" href="https://doi.org/10.1145/23002.23003" target="_top">https://doi.org/10.1145/23002.23003</a>
|
||
|
||
</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>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized vector. This will hold the
|
||
result. It will be resized to the proper size.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>l</code></em>:</span></p></td>
|
||
<td><p>
|
||
The lower limit of the generation interval (inclusive). This must
|
||
be less than or equal to the upper limit, and it must be integral.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>h</code></em>:</span></p></td>
|
||
<td><p>
|
||
The upper limit of the generation interval (inclusive). This must
|
||
be greater than or equal to the lower limit, and it must be integral.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>length</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of random integers to generate.
|
||
</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>
|
||
The error code <code class="constant">IGRAPH_EINVAL</code> is returned in each of the
|
||
following cases: (1) The given lower limit is greater than the
|
||
given upper limit, i.e. <code class="constant">l</code> > <code class="constant">h</code>. (2) Assuming that
|
||
<code class="constant">l</code> < <code class="constant">h</code> and N is the sample size, the above error code is
|
||
returned if N > |<code class="constant">h</code> - <code class="constant">l</code>|, i.e. the sample size exceeds the
|
||
size of the candidate pool.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: according to (Vitter 1987), the expected
|
||
running time is O(length).
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.34.4.2.10.1"></a><p class="title"><b>Example 33.2. File <code class="code">examples/simple/igraph_random_sample.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_vector_int_t V;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="strong"><strong>igraph_vector_int_init</strong></span>(&V, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Nongraph.html#igraph_random_sample" title="3.1. igraph_random_sample — Generates an increasing random sequence of integers.">igraph_random_sample</a></strong></span>(&V, 0, 100, 5);
|
||
<span class="strong"><strong>igraph_vector_int_print</strong></span>(&V);
|
||
<span class="strong"><strong>igraph_vector_int_destroy</strong></span>(&V);
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="random-sampling-of-spatial-points"></a>4. Random sampling of spatial points</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_rng_sample_sphere_surface">4.1. <code class="function">igraph_rng_sample_sphere_surface</code> — Sample points uniformly from the surface of a sphere.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_rng_sample_sphere_volume">4.2. <code class="function">igraph_rng_sample_sphere_volume</code> — Sample points uniformly from the volume of a sphere.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_rng_sample_dirichlet">4.3. <code class="function">igraph_rng_sample_dirichlet</code> — Sample points from a Dirichlet distribution.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_rng_sample_sphere_surface"></a>4.1. <code class="function">igraph_rng_sample_sphere_surface</code> — Sample points uniformly from the surface of a sphere.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.5.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_rng_sample_sphere_surface(
|
||
igraph_rng_t* rng, igraph_int_t dim, igraph_int_t n, igraph_real_t radius,
|
||
igraph_bool_t positive, igraph_matrix_t *res
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The center of the sphere is at the origin.
|
||
|
||
</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>rng</code></em>:</span></p></td>
|
||
<td><p>
|
||
The random number generator to use.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>dim</code></em>:</span></p></td>
|
||
<td><p>
|
||
The dimension of the random vectors.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of vectors to sample.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>radius</code></em>:</span></p></td>
|
||
<td><p>
|
||
Radius of the sphere, it must be positive.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>positive</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to restrict sampling to the positive
|
||
orthant.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized matrix, the result is
|
||
stored here, each column will be a sampled vector. The matrix is
|
||
resized, as needed.
|
||
</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*dim*g), where g is the time complexity of
|
||
generating a standard normal random number.
|
||
|
||
</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-Nongraph.html#igraph_rng_sample_sphere_volume" title="4.2. igraph_rng_sample_sphere_volume — Sample points uniformly from the volume of a sphere."><code class="function">igraph_rng_sample_sphere_volume()</code></a>, <a class="link" href="igraph-Nongraph.html#igraph_rng_sample_dirichlet" title="4.3. igraph_rng_sample_dirichlet — Sample points from a Dirichlet distribution."><code class="function">igraph_rng_sample_dirichlet()</code></a> for other similar samplers.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_rng_sample_sphere_volume"></a>4.2. <code class="function">igraph_rng_sample_sphere_volume</code> — Sample points uniformly from the volume of a sphere.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.5.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_rng_sample_sphere_volume(
|
||
igraph_rng_t* rng, igraph_int_t dim, igraph_int_t n, igraph_real_t radius,
|
||
igraph_bool_t positive, igraph_matrix_t *res
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
The center of the sphere is at the origin.
|
||
|
||
</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>rng</code></em>:</span></p></td>
|
||
<td><p>
|
||
The random number generator to use.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>dim</code></em>:</span></p></td>
|
||
<td><p>
|
||
The dimension of the random vectors.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of vectors to sample.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>radius</code></em>:</span></p></td>
|
||
<td><p>
|
||
Radius of the sphere, it must be positive.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>positive</code></em>:</span></p></td>
|
||
<td><p>
|
||
Whether to restrict sampling to the positive
|
||
orthant.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized matrix, the result is
|
||
stored here, each column will be a sampled vector. The matrix is
|
||
resized, as needed.
|
||
</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*dim*g), where g is the time complexity of
|
||
generating a standard normal random number.
|
||
|
||
</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-Nongraph.html#igraph_rng_sample_sphere_surface" title="4.1. igraph_rng_sample_sphere_surface — Sample points uniformly from the surface of a sphere."><code class="function">igraph_rng_sample_sphere_surface()</code></a>, <a class="link" href="igraph-Nongraph.html#igraph_rng_sample_dirichlet" title="4.3. igraph_rng_sample_dirichlet — Sample points from a Dirichlet distribution."><code class="function">igraph_rng_sample_dirichlet()</code></a> for other similar samplers.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_rng_sample_dirichlet"></a>4.3. <code class="function">igraph_rng_sample_dirichlet</code> — Sample points from a Dirichlet distribution.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.5.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_rng_sample_dirichlet(
|
||
igraph_rng_t* rng, igraph_int_t n, const igraph_vector_t *alpha,
|
||
igraph_matrix_t *res
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
</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>rng</code></em>:</span></p></td>
|
||
<td><p>
|
||
The random number generator to use.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>n</code></em>:</span></p></td>
|
||
<td><p>
|
||
The number of vectors to sample.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>alpha</code></em>:</span></p></td>
|
||
<td><p>
|
||
The parameters of the Dirichlet distribution. They
|
||
must be positive. The length of this vector gives the dimension
|
||
of the generated samples.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>res</code></em>:</span></p></td>
|
||
<td><p>
|
||
Pointer to an initialized matrix, the result is stored
|
||
here, one sample in each column. It will be resized, as needed.
|
||
</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 * dim * g), where dim is the dimension of the
|
||
sample vectors, set by the length of alpha, and g is the time
|
||
complexity of sampling from a Gamma distribution.
|
||
|
||
</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-Nongraph.html#igraph_rng_sample_sphere_surface" title="4.1. igraph_rng_sample_sphere_surface — Sample points uniformly from the surface of a sphere."><code class="function">igraph_rng_sample_sphere_surface()</code></a> and
|
||
<a class="link" href="igraph-Nongraph.html#igraph_rng_sample_sphere_volume" title="4.2. igraph_rng_sample_sphere_volume — Sample points uniformly from the volume of a sphere."><code class="function">igraph_rng_sample_sphere_volume()</code></a> for other methods to sample
|
||
latent vectors.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="fitting-powerlaw-distributions-to-empirical-data"></a>5. Fitting power-law distributions to empirical data</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_plfit_result_t">5.1. <code class="function">igraph_plfit_result_t</code> — Result of fitting a power-law distribution to a vector.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_power_law_fit">5.2. <code class="function">igraph_power_law_fit</code> — Fits a power-law distribution to a vector of numbers.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_plfit_result_calculate_p_value">5.3. <code class="function">igraph_plfit_result_calculate_p_value</code> — Calculates the p-value of a fitted power-law model.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_plfit_result_t"></a>5.1. <code class="function">igraph_plfit_result_t</code> — Result of fitting a power-law distribution to a vector.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.6.2.2"></a><p>
|
||
</p>
|
||
<pre class="programlisting">
|
||
typedef struct igraph_plfit_result_t {
|
||
igraph_bool_t continuous;
|
||
igraph_real_t alpha;
|
||
igraph_real_t xmin;
|
||
igraph_real_t L;
|
||
igraph_real_t D;
|
||
const igraph_vector_t* data;
|
||
} igraph_plfit_result_t;
|
||
</pre>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
</p>
|
||
<p>This data structure contains the result of <a class="link" href="igraph-Nongraph.html#igraph_power_law_fit" title="5.2. igraph_power_law_fit — Fits a power-law distribution to a vector of numbers."><code class="function">igraph_power_law_fit()</code></a>,
|
||
which tries to fit a power-law distribution to a vector of numbers. The
|
||
structure contains the following members:
|
||
|
||
</p>
|
||
<p><b>Values: </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"><code class="constant">continuous</code>:</span></p></td>
|
||
<td><p>
|
||
Whether the fitted power-law distribution was continuous
|
||
or discrete.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">alpha</code>:</span></p></td>
|
||
<td><p>
|
||
The exponent of the fitted power-law distribution.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">xmin</code>:</span></p></td>
|
||
<td><p>
|
||
The minimum value from which the power-law distribution was
|
||
fitted. In other words, only the values larger than <code class="constant">xmin</code>
|
||
were used from the input vector.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">L</code>:</span></p></td>
|
||
<td><p>
|
||
The log-likelihood of the fitted parameters; in other words,
|
||
the probability of observing the input vector given the
|
||
parameters.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">D</code>:</span></p></td>
|
||
<td><p>
|
||
The test statistic of a Kolmogorov-Smirnov test that compares
|
||
the fitted distribution with the input vector. Smaller scores
|
||
denote better fit.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">p</code>:</span></p></td>
|
||
<td><p>
|
||
The p-value of the Kolmogorov-Smirnov test; <code class="constant">NaN</code> if it has
|
||
not been calculated yet. Small p-values (less than 0.05)
|
||
indicate that the test rejected the hypothesis that the
|
||
original data could have been drawn from the fitted power-law
|
||
distribution.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><code class="constant">data</code>:</span></p></td>
|
||
<td><p>
|
||
The vector containing the original input data. May not be valid
|
||
any more if the caller already destroyed the vector.</p></td>
|
||
</tr>
|
||
</tbody>
|
||
</table></div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_power_law_fit"></a>5.2. <code class="function">igraph_power_law_fit</code> — Fits a power-law distribution to a vector of numbers.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.6.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_power_law_fit(
|
||
const igraph_vector_t* data, igraph_plfit_result_t* result,
|
||
igraph_real_t xmin, igraph_bool_t force_continuous
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
This function fits a power-law distribution to a vector containing samples
|
||
from a distribution (that is assumed to follow a power-law of course). In
|
||
a power-law distribution, it is generally assumed that P(X=x) is
|
||
proportional to x<sup>-alpha</sup>, where x is a positive number and alpha
|
||
is greater than 1. In many real-world cases, the power-law behaviour kicks
|
||
in only above a threshold value <span class="emphasis"><em>xmin.</em></span> The goal of this functions is to
|
||
determine <span class="emphasis"><em>alpha</em></span> if <span class="emphasis"><em>xmin</em></span> is given, or to determine <span class="emphasis"><em>xmin</em></span> and the
|
||
corresponding value of <span class="emphasis"><em>alpha.</em></span>
|
||
|
||
</p>
|
||
<p>
|
||
The function uses the maximum likelihood principle to determine <span class="emphasis"><em>alpha</em></span>
|
||
for a given <span class="emphasis"><em>xmin;</em></span> in other words, the function will return the <span class="emphasis"><em>alpha</em></span>
|
||
value for which the probability of drawing the given sample is the highest.
|
||
When <span class="emphasis"><em>xmin</em></span> is not given in advance, the algorithm will attempt to find
|
||
the optimal <span class="emphasis"><em>xmin</em></span> value for which the p-value of a Kolmogorov-Smirnov
|
||
test between the fitted distribution and the original sample is the largest.
|
||
The function uses the method of Clauset, Shalizi and Newman to calculate the
|
||
parameters of the fitted distribution. See the following reference for
|
||
details:
|
||
|
||
</p>
|
||
<p>
|
||
Aaron Clauset, Cosma R. Shalizi and Mark E.J. Newman: Power-law
|
||
distributions in empirical data. SIAM Review 51(4):661-703, 2009.
|
||
<a class="ulink" href="https://doi.org/10.1137/070710111" target="_top">https://doi.org/10.1137/070710111</a>
|
||
|
||
</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>data</code></em>:</span></p></td>
|
||
<td><p>
|
||
vector containing the samples for which a power-law distribution
|
||
is to be fitted. Note that you have to provide the <span class="emphasis"><em>samples,</em></span>
|
||
not the probability density function or the cumulative
|
||
distribution function. For example, if you wish to fit
|
||
a power-law to the degrees of a graph, you can use the output of
|
||
<a class="link" href="igraph-Basic.html#igraph_degree" title="5.2.14. igraph_degree — The degree of some vertices in a graph."><code class="function">igraph_degree</code></a> directly as an input argument to
|
||
<a class="link" href="igraph-Nongraph.html#igraph_power_law_fit" title="5.2. igraph_power_law_fit — Fits a power-law distribution to a vector of numbers."><code class="function">igraph_power_law_fit</code></a>
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>result</code></em>:</span></p></td>
|
||
<td><p>
|
||
the result of the fitting algorithm. See <a class="link" href="igraph-Nongraph.html#igraph_plfit_result_t" title="5.1. igraph_plfit_result_t — Result of fitting a power-law distribution to a vector."><code class="function">igraph_plfit_result_t</code></a>
|
||
for more details. Note that the p-value of the fit is <span class="emphasis"><em>not</em></span>
|
||
calculated by default as it is time-consuming; you need to call
|
||
<a class="link" href="igraph-Nongraph.html#igraph_plfit_result_calculate_p_value" title="5.3. igraph_plfit_result_calculate_p_value — Calculates the p-value of a fitted power-law model."><code class="function">igraph_plfit_result_calculate_p_value()</code></a> to calculate the
|
||
p-value itself
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>xmin</code></em>:</span></p></td>
|
||
<td><p>
|
||
the minimum value in the sample vector where the power-law
|
||
behaviour is expected to kick in. Samples smaller than <code class="constant">xmin</code>
|
||
will be ignored by the algorithm. Pass zero here if you want to
|
||
include all the samples. If <code class="constant">xmin</code> is negative, the algorithm
|
||
will attempt to determine its best value automatically.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>force_continuous</code></em>:</span></p></td>
|
||
<td><p>
|
||
assume that the samples in the <code class="constant">data</code> argument come
|
||
from a continuous distribution even if the sample vector
|
||
contains integer values only (by chance). If this argument is
|
||
false, igraph will assume a continuous distribution if at least
|
||
one sample is non-integer and assume a discrete distribution
|
||
otherwise.
|
||
</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:
|
||
<code class="constant">IGRAPH_ENOMEM</code>: not enough memory
|
||
<code class="constant">IGRAPH_EINVAL</code>: one of the arguments is invalid
|
||
<code class="constant">IGRAPH_EOVERFLOW</code>: overflow during the fitting process
|
||
<code class="constant">IGRAPH_EUNDERFLOW</code>: underflow during the fitting process
|
||
<code class="constant">IGRAPH_FAILURE</code>: the underlying algorithm signaled a failure
|
||
without returning a more specific error code
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
Time complexity: in the continuous case, O(n log(n)) if <code class="constant">xmin</code> is given.
|
||
In the discrete case, the time complexity is dominated by the complexity of
|
||
the underlying L-BFGS algorithm that is used to optimize alpha. If <code class="constant">xmin</code>
|
||
is not given, the time complexity is multiplied by the number of unique
|
||
samples in the input vector (although it should be faster in practice).
|
||
|
||
</p>
|
||
<div class="hideshow" onClick="toggle(this, event)">
|
||
<div class="example">
|
||
<a name="id-1.34.6.3.10.3"></a><p class="title"><b>Example 33.3. File <code class="code">examples/simple/igraph_power_law_fit.c</code></b></p>
|
||
<div class="example-contents">
|
||
<pre class="programlisting"><span class="strong"><strong>#include</strong></span> <igraph.h>
|
||
|
||
int <span class="strong"><strong>main</strong></span>(void) {
|
||
igraph_t g;
|
||
<a class="link" href="igraph-Data-structures.html#igraph_vector_t" title="2.1. About igraph_vector_t objects">igraph_vector_t</a> degree;
|
||
<a class="link" href="igraph-Nongraph.html#igraph_plfit_result_t" title="5.1. igraph_plfit_result_t — Result of fitting a power-law distribution to a vector.">igraph_plfit_result_t</a> model;
|
||
|
||
<span class="emphasis"><em>/* Initialize the library. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_setup" title="4.1. igraph_setup — Initializes the igraph library.">igraph_setup</a></strong></span>();
|
||
|
||
<span class="emphasis"><em>/* Seed random number generator to ensure reproducibility. */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_seed" title="3.3. igraph_rng_seed — Seeds a random number generator.">igraph_rng_seed</a></strong></span>(<span class="strong"><strong><a class="link" href="igraph-Random.html#igraph_rng_default" title="2.1. igraph_rng_default — Query the default random number generator.">igraph_rng_default</a></strong></span>(), 42);
|
||
|
||
<span class="emphasis"><em>/* Generate a BA network; degree distribution is supposed to be a power-law</em></span>
|
||
<span class="emphasis"><em> * if the graph is large enough */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Games.html#igraph_barabasi_game" title="2.1. igraph_barabasi_game — Generates a graph based on the Barabási-Albert model.">igraph_barabasi_game</a></strong></span>(
|
||
&g, 10000, <span class="emphasis"><em>/*power=*/</em></span> 1, <span class="emphasis"><em>/*m=*/</em></span> 2,
|
||
<span class="emphasis"><em>/* outseq= */</em></span> 0, <span class="emphasis"><em>/* outpref= */</em></span> 0, <span class="emphasis"><em>/*A=*/</em></span> 1,
|
||
IGRAPH_UNDIRECTED, IGRAPH_BARABASI_BAG,
|
||
<span class="emphasis"><em>/*start_from=*/</em></span> 0
|
||
);
|
||
|
||
<span class="emphasis"><em>/* Get the vertex degrees. We use igraph_strength() because it stores its</em></span>
|
||
<span class="emphasis"><em> * result in an igraph_vector_t */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_init" title="2.2.1. igraph_vector_init — Initializes a vector object (constructor).">igraph_vector_init</a></strong></span>(&degree, 0);
|
||
<span class="strong"><strong><a class="link" href="igraph-Structural.html#igraph_strength" title="11.11. igraph_strength — Strength of the vertices, also called weighted vertex degree.">igraph_strength</a></strong></span>(&g, &degree, <span class="strong"><strong><a class="link" href="igraph-Iterators.html#igraph_vss_all" title="4.1. igraph_vss_all — All vertices of a graph (immediate version).">igraph_vss_all</a></strong></span>(), IGRAPH_ALL, IGRAPH_NO_LOOPS, 0);
|
||
|
||
<span class="emphasis"><em>/* Fit a power-law to the degrees */</em></span>
|
||
<span class="strong"><strong><a class="link" href="igraph-Nongraph.html#igraph_power_law_fit" title="5.2. igraph_power_law_fit — Fits a power-law distribution to a vector of numbers.">igraph_power_law_fit</a></strong></span>(
|
||
&degree, &model, <span class="emphasis"><em>/* xmin = */</em></span> -1,
|
||
<span class="emphasis"><em>/* force_continuous = */</em></span> 0
|
||
);
|
||
|
||
<span class="emphasis"><em>/* If you also need a p-value: */</em></span>
|
||
<span class="emphasis"><em>/* igraph_plfit_result_calculate_p_value(&model, &p, 0.001); */</em></span>
|
||
|
||
<span class="strong"><strong>printf</strong></span>("alpha = %.5f\n", model.alpha);
|
||
<span class="strong"><strong>printf</strong></span>("xmin = %.5f\n", model.xmin);
|
||
<span class="strong"><strong>printf</strong></span>("log-likelihood = %.5f\n", model.L);
|
||
|
||
<span class="strong"><strong><a class="link" href="igraph-Data-structures.html#igraph_vector_destroy" title="2.2.5. igraph_vector_destroy — Destroys a vector object.">igraph_vector_destroy</a></strong></span>(&degree);
|
||
<span class="strong"><strong><a class="link" href="igraph-Basic.html#igraph_destroy" title="5.1.4. igraph_destroy — Frees the memory allocated for a graph object.">igraph_destroy</a></strong></span>(&g);
|
||
|
||
<span class="strong"><strong>return</strong></span> 0;
|
||
}
|
||
</pre>
|
||
<p></p>
|
||
</div>
|
||
</div>
|
||
<br class="example-break">
|
||
</div>
|
||
<p>
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_plfit_result_calculate_p_value"></a>5.3. <code class="function">igraph_plfit_result_calculate_p_value</code> — Calculates the p-value of a fitted power-law model.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.6.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_error_t igraph_plfit_result_calculate_p_value(
|
||
const igraph_plfit_result_t* model, igraph_real_t* result, igraph_real_t precision
|
||
);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
|
||
</p>
|
||
<p>
|
||
The p-value is calculated by resampling the input data many times in a way
|
||
that the part below the fitted <code class="constant">x_min</code> threshold is resampled from the
|
||
input data itself, while the part above the fitted <code class="constant">x_min</code> threshold is
|
||
drawn from the fitted power-law function. A Kolmogorov-Smirnov test is then
|
||
performed for each resampled dataset and its test statistic is compared with the
|
||
observed test statistic from the original dataset. The fraction of resampled
|
||
datasets that have a <span class="emphasis"><em>higher</em></span> test statistic is the returned p-value.
|
||
|
||
</p>
|
||
<p>
|
||
Note that the precision of the returned p-value depends on the number of
|
||
resampling attempts. The number of resampling trials is determined by
|
||
0.25 divided by the square of the required precision. For instance, a required
|
||
precision of 0.01 means that 2500 samples will be drawn.
|
||
|
||
</p>
|
||
<p>
|
||
If igraph is compiled with OpenMP support, this function will use parallel
|
||
OpenMP threads for the resampling. Each OpenMP thread gets its own instance
|
||
of a random number generator. However, since the scheduling of OpenMP threads
|
||
is outside our control, we cannot guarantee how many resampling instances the
|
||
threads are asked to execute, thus it may happen that the random number
|
||
generators are used differently between runs. If you want to obtain
|
||
reproducible results, seed igraph's master RNG appropriately, and force the
|
||
number of OpenMP threads to 1 early in your program, either by calling
|
||
<code class="literal">omp_set_num_threads(1)</code> or by setting the value of the <code class="constant">OMP_NUM_THREADS</code>
|
||
environment variable to 1.
|
||
|
||
</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>model</code></em>:</span></p></td>
|
||
<td><p>
|
||
The fitted power-law model from the <a class="link" href="igraph-Nongraph.html#igraph_power_law_fit" title="5.2. igraph_power_law_fit — Fits a power-law distribution to a vector of numbers."><code class="function">igraph_power_law_fit()</code></a>
|
||
function
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>result</code></em>:</span></p></td>
|
||
<td><p>
|
||
The calculated p-value is returned here
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>precision</code></em>:</span></p></td>
|
||
<td><p>
|
||
The desired precision of the p-value. Higher values correspond
|
||
to longer calculation time.
|
||
</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>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="compare-floats-with-tolerance"></a>6. Comparing floats with a tolerance</h2></div></div></div>
|
||
<div class="toc"><dl class="toc">
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_cmp_epsilon">6.1. <code class="function">igraph_cmp_epsilon</code> — Compare two double-precision floats with a tolerance.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_almost_equals">6.2. <code class="function">igraph_almost_equals</code> — Compare two double-precision floats with a tolerance.</a></span></dt>
|
||
<dt><span class="section"><a href="igraph-Nongraph.html#igraph_complex_almost_equals">6.3. <code class="function">igraph_complex_almost_equals</code> — Compare two complex numbers with a tolerance.</a></span></dt>
|
||
</dl></div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_cmp_epsilon"></a>6.1. <code class="function">igraph_cmp_epsilon</code> — Compare two double-precision floats with a tolerance.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.7.2.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
int igraph_cmp_epsilon(double a, double b, double eps);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Determines whether two double-precision floats are "almost equal"
|
||
to each other with a given level of tolerance on the relative error.
|
||
|
||
</p>
|
||
<p>
|
||
The function supports infinities and NaN values. NaN values are considered
|
||
not equal to any other value (even another NaN), but the ordering is
|
||
arbitrary; in other words, we only guarantee that comparing a NaN with
|
||
any other value will not return zero. Positive infinity is considered to
|
||
be greater than any finite value with any tolerance. Negative infinity is
|
||
considered to be smaller than any finite value with any tolerance.
|
||
Positive infinity is considered to be equal to another positive infinity
|
||
with any tolerance. Negative infinity is considered to be equal to another
|
||
negative infinity with any tolerance.
|
||
|
||
</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>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first float.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second float.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eps</code></em>:</span></p></td>
|
||
<td><p>
|
||
The level of tolerance on the relative error. The relative
|
||
error is defined as <code class="literal">abs(a-b) / (abs(a) + abs(b))</code>. The
|
||
two numbers are considered equal if this is less than <code class="constant">eps</code>.
|
||
Negative epsilon values are not allowed; the returned value will
|
||
be undefined in this case. Zero means to do an exact comparison
|
||
without tolerance.</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>
|
||
Zero if the two floats are nearly equal to each other within
|
||
the given level of tolerance, positive number if the first float is
|
||
larger, negative number if the second float is larger.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_almost_equals"></a>6.2. <code class="function">igraph_almost_equals</code> — Compare two double-precision floats with a tolerance.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.7.3.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_bool_t igraph_almost_equals(double a, double b, double eps);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Determines whether two double-precision floats are "almost equal"
|
||
to each other with a given level of tolerance on the relative error.
|
||
|
||
</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>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first float.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second float.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eps</code></em>:</span></p></td>
|
||
<td><p>
|
||
The level of tolerance on the relative error. The relative
|
||
error is defined as <code class="literal">abs(a-b) / (abs(a) + abs(b))</code>. The
|
||
two numbers are considered equal if this is less than <code class="constant">eps</code>.</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>
|
||
True if the two floats are nearly equal to each other within
|
||
the given level of tolerance, false otherwise.
|
||
</p></td>
|
||
</tr></tbody>
|
||
</table></div>
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
<div class="section">
|
||
<div class="titlepage"><div><div><h3 class="title">
|
||
<a name="igraph_complex_almost_equals"></a>6.3. <code class="function">igraph_complex_almost_equals</code> — Compare two complex numbers with a tolerance.</h3></div></div></div>
|
||
<a class="indexterm" name="id-1.34.7.4.2"></a><p>
|
||
</p>
|
||
<div class="informalexample"><pre class="programlisting">
|
||
igraph_bool_t igraph_complex_almost_equals(igraph_complex_t a,
|
||
igraph_complex_t b,
|
||
igraph_real_t eps);
|
||
</pre></div>
|
||
<p>
|
||
</p>
|
||
<p>
|
||
|
||
|
||
|
||
Determines whether two complex numbers are "almost equal"
|
||
to each other with a given level of tolerance on the relative error.
|
||
|
||
</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>a</code></em>:</span></p></td>
|
||
<td><p>
|
||
The first complex number.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>b</code></em>:</span></p></td>
|
||
<td><p>
|
||
The second complex number.
|
||
</p></td>
|
||
</tr>
|
||
<tr>
|
||
<td><p><span class="term"><em class="parameter"><code>eps</code></em>:</span></p></td>
|
||
<td><p>
|
||
The level of tolerance on the relative error. The relative
|
||
error is defined as <code class="literal">abs(a-b) / (abs(a) + abs(b))</code>. The
|
||
two numbers are considered equal if this is less than <code class="constant">eps</code>.</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>
|
||
True if the two complex numbers are nearly equal to each other within
|
||
the given level of tolerance, false otherwise.
|
||
</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-Linalg.html"><b>← Chapter 32. Using BLAS, LAPACK and ARPACK for igraph matrices and graphs</b></a></td>
|
||
<td align="right"><a accesskey="n" href="igraph-Advanced.html"><b>Chapter 34. Advanced igraph programming →</b></a></td>
|
||
</tr></table>
|
||
</body>
|
||
</html>
|