Skip to content

Commit

Permalink
deploy: 4a3407c
Browse files Browse the repository at this point in the history
  • Loading branch information
BenJourdan committed Nov 11, 2024
1 parent 0150047 commit 1da2123
Show file tree
Hide file tree
Showing 9 changed files with 963 additions and 4 deletions.
177 changes: 177 additions & 0 deletions _modules/coreset_sc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@


<!DOCTYPE html>
<html class="writer-html5" lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>coreset_sc &mdash; coreset-sc 0.01 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
<link rel="stylesheet" type="text/css" href="../_static/css/theme.css?v=e59714d7" />


<script src="../_static/jquery.js?v=5d32c60e"></script>
<script src="../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script>
<script src="../_static/documentation_options.js?v=6ca3c713"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/js/theme.js"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head>

<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search" >



<a href="../index.html" class="icon icon-home">
coreset-sc
</a>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
<p class="caption" role="heading"><span class="caption-text">Contents:</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../usage.html">Usage</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api.html">API Reference</a></li>
</ul>

</div>
</div>
</nav>

<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../index.html">coreset-sc</a>
</nav>

<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="Page navigation">
<ul class="wy-breadcrumbs">
<li><a href="../index.html" class="icon icon-home" aria-label="Home"></a></li>
<li class="breadcrumb-item"><a href="index.html">Module code</a></li>
<li class="breadcrumb-item active">coreset_sc</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">

<h1>Source code for coreset_sc</h1><div class="highlight"><pre>
<span></span><span class="kn">from</span> <span class="nn">.</span> <span class="kn">import</span> <span class="n">coreset_sc</span><span class="p">,</span> <span class="n">utils</span>
<span class="kn">from</span> <span class="nn">.csc</span> <span class="kn">import</span> <span class="n">CoresetSpectralClustering</span> <span class="k">as</span> <span class="n">CoresetSpectralClustering</span>

<span class="c1"># import maturin_import_hook</span>
<span class="c1"># import scipy</span>
<span class="c1"># import stag.random</span>
<span class="c1"># from maturin_import_hook.settings import MaturinSettings</span>

<span class="c1"># maturin_import_hook.install(</span>
<span class="c1"># enable_project_importer=True,</span>
<span class="c1"># enable_rs_file_importer=True,</span>
<span class="c1"># settings=MaturinSettings(</span>
<span class="c1"># release=True,</span>
<span class="c1"># strip=True,</span>
<span class="c1"># ),</span>
<span class="c1"># show_warnings=False,</span>
<span class="c1"># )</span>


<div class="viewcode-block" id="gen_sbm">
<a class="viewcode-back" href="../api.html#coreset_sc.gen_sbm">[docs]</a>
<span class="k">def</span> <span class="nf">gen_sbm</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">q</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Generate an approximate sample from a Stochastic Block Model (SBM) graph.</span>

<span class="sd"> Parameters</span>
<span class="sd"> ----------</span>
<span class="sd"> n : int</span>
<span class="sd"> Number of nodes in each cluster.</span>
<span class="sd"> k : int</span>
<span class="sd"> Number of clusters.</span>
<span class="sd"> p : float</span>
<span class="sd"> Probability of an edge within the same cluster.</span>
<span class="sd"> q : float</span>
<span class="sd"> Probability of an edge between different clusters.</span>

<span class="sd"> Returns</span>
<span class="sd"> -------</span>
<span class="sd"> adj_mat : scipy.sparse.csr_matrix, shape = (n*k, n*k)</span>
<span class="sd"> The symmetric adjacency matrix of the generated graph with self loops added.</span>
<span class="sd"> labels : numpy.ndarray, shape = (n*k,)</span>
<span class="sd"> The ground truth cluster labels</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span> <span class="s2">&quot;n must be an integer&quot;</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">k</span><span class="p">,</span> <span class="nb">int</span><span class="p">),</span> <span class="s2">&quot;k must be an integer&quot;</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span> <span class="s2">&quot;p must be a float&quot;</span>
<span class="k">assert</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">q</span><span class="p">,</span> <span class="nb">float</span><span class="p">),</span> <span class="s2">&quot;q must be a float&quot;</span>
<span class="k">assert</span> <span class="n">n</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;n must be greater than 0&quot;</span>
<span class="k">assert</span> <span class="n">k</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">,</span> <span class="s2">&quot;k must be greater than 0&quot;</span>
<span class="k">assert</span> <span class="mi">0</span> <span class="o">&lt;=</span> <span class="n">p</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;p must be between 0 and 1&quot;</span>
<span class="k">assert</span> <span class="mi">0</span> <span class="o">&lt;=</span> <span class="n">q</span> <span class="o">&lt;=</span> <span class="mi">1</span><span class="p">,</span> <span class="s2">&quot;q must be between 0 and 1&quot;</span>

<span class="n">size</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">indices</span><span class="p">,</span> <span class="n">indptr</span><span class="p">,</span> <span class="n">labels</span> <span class="o">=</span> <span class="n">coreset_sc</span><span class="o">.</span><span class="n">gen_sbm</span><span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="n">k</span><span class="p">,</span> <span class="n">p</span><span class="p">,</span> <span class="n">q</span><span class="p">)</span>
<span class="n">adj_mat</span> <span class="o">=</span> <span class="n">utils</span><span class="o">.</span><span class="n">convert_to_csr_matrix</span><span class="p">(</span><span class="n">size</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">indptr</span><span class="p">,</span> <span class="n">indices</span><span class="p">)</span>
<span class="k">return</span> <span class="n">adj_mat</span><span class="p">,</span> <span class="n">labels</span></div>



<span class="c1"># def stag_sbm(n, k, p, q):</span>
<span class="c1"># assert isinstance(n, int), &quot;n must be an integer&quot;</span>
<span class="c1"># assert isinstance(k, int), &quot;k must be an integer&quot;</span>
<span class="c1"># assert isinstance(p, float), &quot;p must be a float&quot;</span>
<span class="c1"># assert isinstance(q, float), &quot;q must be a float&quot;</span>
<span class="c1"># assert n &gt; 0, &quot;n must be greater than 0&quot;</span>
<span class="c1"># assert k &gt; 0, &quot;k must be greater than 0&quot;</span>
<span class="c1"># assert 0 &lt;= p &lt;= 1, &quot;p must be between 0 and 1&quot;</span>
<span class="c1"># assert 0 &lt;= q &lt;= 1, &quot;q must be between 0 and 1&quot;</span>
<span class="c1"># N = int(n * k)</span>
<span class="c1"># g = stag.random.sbm(N, k, p, q, False)</span>
<span class="c1"># adj = g.adjacency().to_scipy()</span>
<span class="c1"># adj = (adj + scipy.sparse.eye(int(n * k))).tocsr()</span>
<span class="c1"># labels = stag.random.sbm_gt_labels(N, k)</span>

<span class="c1"># return adj, labels</span>
</pre></div>

</div>
</div>
<footer>

<hr/>

<div role="contentinfo">
<p>&#169; Copyright 2024, Ben Jourdan.</p>
</div>

Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
provided by <a href="https://readthedocs.org">Read the Docs</a>.


</footer>
</div>
</div>
</section>
</div>
<script>
jQuery(function () {
SphinxRtdTheme.Navigation.enable(true);
});
</script>

</body>
</html>
Loading

0 comments on commit 1da2123

Please sign in to comment.