blob: 334457038c3e81a909eb9a725370a432f410d149 [file] [log] [blame]
<!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" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Density Sketch &mdash; datasketches 0.1 documentation</title>
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<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=2709fde1"></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" />
<link rel="next" title="Random Sampling Sketches" href="../sampling/index.html" />
<link rel="prev" title="Vector Sketches" href="index.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">
datasketches
</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">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../distinct_counting/index.html">Distinct Counting</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../quantiles/index.html">Quantiles Sketches</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../frequency/index.html">Frequency Sketches</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Vector Sketches</a><ul class="current">
<li class="toctree-l2 current"><a class="current reference internal" href="#">Density Sketch</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#datasketches.density_sketch"><code class="docutils literal notranslate"><span class="pre">density_sketch</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.deserialize"><code class="docutils literal notranslate"><span class="pre">density_sketch.deserialize()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.__init__"><code class="docutils literal notranslate"><span class="pre">density_sketch.__init__()</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.dim"><code class="docutils literal notranslate"><span class="pre">density_sketch.dim</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.get_estimate"><code class="docutils literal notranslate"><span class="pre">density_sketch.get_estimate</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.is_empty"><code class="docutils literal notranslate"><span class="pre">density_sketch.is_empty</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.is_estimation_mode"><code class="docutils literal notranslate"><span class="pre">density_sketch.is_estimation_mode</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.k"><code class="docutils literal notranslate"><span class="pre">density_sketch.k</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.merge"><code class="docutils literal notranslate"><span class="pre">density_sketch.merge</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.n"><code class="docutils literal notranslate"><span class="pre">density_sketch.n</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.num_retained"><code class="docutils literal notranslate"><span class="pre">density_sketch.num_retained</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.serialize"><code class="docutils literal notranslate"><span class="pre">density_sketch.serialize</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.to_string"><code class="docutils literal notranslate"><span class="pre">density_sketch.to_string</span></code></a></li>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.density_sketch.update"><code class="docutils literal notranslate"><span class="pre">density_sketch.update</span></code></a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../sampling/index.html">Random Sampling Sketches</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../helper/index.html">Helper Classes</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">datasketches</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">Vector Sketches</a></li>
<li class="breadcrumb-item active">Density Sketch</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/vector/density_sketch.rst.txt" rel="nofollow"> View page source</a>
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<section id="density-sketch">
<h1>Density Sketch<a class="headerlink" href="#density-sketch" title="Link to this heading"></a></h1>
<p>Builds a coreset from the given set of input points.
Provides density estimate at a given point.</p>
<p>Based on the following paper: Zohar Karnin, Edo Liberty
“Discrepancy, Coresets, and Sketches in Machine Learning”
<a class="reference external" href="https://proceedings.mlr.press/v99/karnin19a/karnin19a.pdf">https://proceedings.mlr.press/v99/karnin19a/karnin19a.pdf</a></p>
<p>Inspired by the following implementation: <a class="reference external" href="https://github.com/edoliberty/streaming-quantiles/blob/f688c8161a25582457b0a09deb4630a81406293b/gde.py">https://github.com/edoliberty/streaming-quantiles/blob/f688c8161a25582457b0a09deb4630a81406293b/gde.py</a></p>
<p>Requires the use of a <a class="reference internal" href="../helper/kernel.html#datasketches.KernelFunction" title="datasketches.KernelFunction"><code class="xref py py-class docutils literal notranslate"><span class="pre">KernelFunction</span></code></a> to compute the distance between two vectors.</p>
<dl class="py class">
<dt class="sig sig-object py" id="datasketches.density_sketch">
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">density_sketch</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">args</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">kwargs</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#datasketches.density_sketch" title="Link to this definition"></a></dt>
<dd><p class="rubric">Static Methods:</p>
<dl class="py method">
<dt class="sig sig-object py" id="datasketches.density_sketch.deserialize">
<span class="sig-name descname"><span class="pre">deserialize</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bytes</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">bytes</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="../helper/kernel.html#datasketches.KernelFunction" title="_datasketches.KernelFunction"><span class="pre">_datasketches.KernelFunction</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><a class="reference internal" href="#datasketches.density_sketch" title="_datasketches.density_sketch"><span class="pre">_datasketches.density_sketch</span></a></span></span><a class="headerlink" href="#datasketches.density_sketch.deserialize" title="Link to this definition"></a></dt>
<dd><p>Reads a bytes object and returns the corresponding density_sketch</p>
</dd></dl>
<p class="rubric">Non-static Methods:</p>
<dl class="py method">
<dt class="sig sig-object py" id="datasketches.density_sketch.__init__">
<span class="sig-name descname"><span class="pre">__init__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">self</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">k</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dim</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">int</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">kernel</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><a class="reference internal" href="../helper/kernel.html#datasketches.KernelFunction" title="_datasketches.KernelFunction"><span class="pre">_datasketches.KernelFunction</span></a></span></em><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">None</span></span></span><a class="headerlink" href="#datasketches.density_sketch.__init__" title="Link to this definition"></a></dt>
<dd><p>Creates a new density sketch</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>k</strong> (<em>int</em>) – controls the size and error of the sketch</p></li>
<li><p><strong>dim</strong> (<em>int</em>) – dimension of the input data</p></li>
<li><p><strong>kernel</strong> (<a class="reference internal" href="../helper/kernel.html#datasketches.KernelFunction" title="datasketches.KernelFunction"><em>KernelFunction</em></a>) – instance of a kernel</p></li>
</ul>
</dd>
</dl>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="datasketches.density_sketch.dim">
<em class="property"><span class="k"><span class="pre">property</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">dim</span></span><a class="headerlink" href="#datasketches.density_sketch.dim" title="Link to this definition"></a></dt>
<dd><p>The configured parameter dim</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.get_estimate">
<span class="sig-name descname"><span class="pre">get_estimate</span></span><a class="headerlink" href="#datasketches.density_sketch.get_estimate" title="Link to this definition"></a></dt>
<dd><p>Returns an approximate density at the given point</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.is_empty">
<span class="sig-name descname"><span class="pre">is_empty</span></span><a class="headerlink" href="#datasketches.density_sketch.is_empty" title="Link to this definition"></a></dt>
<dd><p>Returns True if the sketch is empty, otherwise False</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.is_estimation_mode">
<span class="sig-name descname"><span class="pre">is_estimation_mode</span></span><a class="headerlink" href="#datasketches.density_sketch.is_estimation_mode" title="Link to this definition"></a></dt>
<dd><p>Returns True if the sketch is in estimation mode, otherwise False</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="datasketches.density_sketch.k">
<em class="property"><span class="k"><span class="pre">property</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">k</span></span><a class="headerlink" href="#datasketches.density_sketch.k" title="Link to this definition"></a></dt>
<dd><p>The configured parameter k</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.merge">
<span class="sig-name descname"><span class="pre">merge</span></span><a class="headerlink" href="#datasketches.density_sketch.merge" title="Link to this definition"></a></dt>
<dd><p>Merges the provided sketch into this one</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="datasketches.density_sketch.n">
<em class="property"><span class="k"><span class="pre">property</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">n</span></span><a class="headerlink" href="#datasketches.density_sketch.n" title="Link to this definition"></a></dt>
<dd><p>The length of the input stream</p>
</dd></dl>
<dl class="py property">
<dt class="sig sig-object py" id="datasketches.density_sketch.num_retained">
<em class="property"><span class="k"><span class="pre">property</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">num_retained</span></span><a class="headerlink" href="#datasketches.density_sketch.num_retained" title="Link to this definition"></a></dt>
<dd><p>The number of retained items (samples) in the sketch</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.serialize">
<span class="sig-name descname"><span class="pre">serialize</span></span><a class="headerlink" href="#datasketches.density_sketch.serialize" title="Link to this definition"></a></dt>
<dd><p>Serializes the sketch into a bytes object</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.to_string">
<span class="sig-name descname"><span class="pre">to_string</span></span><a class="headerlink" href="#datasketches.density_sketch.to_string" title="Link to this definition"></a></dt>
<dd><p>Produces a string summary of the sketch</p>
</dd></dl>
<dl class="py attribute">
<dt class="sig sig-object py" id="datasketches.density_sketch.update">
<span class="sig-name descname"><span class="pre">update</span></span><a class="headerlink" href="#datasketches.density_sketch.update" title="Link to this definition"></a></dt>
<dd><p>Updates the sketch with the given vector</p>
</dd></dl>
</dd></dl>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="index.html" class="btn btn-neutral float-left" title="Vector Sketches" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
<a href="../sampling/index.html" class="btn btn-neutral float-right" title="Random Sampling Sketches" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a>
</div>
<hr/>
<div role="contentinfo">
<p>&#169; Copyright 2023.</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>