blob: f3a8af8c22ac2195647d06d2a56784154a8b2f03 [file]
<!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>Kernel Function &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="prev" title="Kolmogorov-Smirnov Test" href="ks_test.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>
<li class="toctree-l1"><a class="reference internal" href="../vector/index.html">Vector Sketches</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../sampling/index.html">Random Sampling Sketches</a></li>
</ul>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="index.html">Helper Classes</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="serde.html">Serialize/Deserialize (SerDe)</a></li>
<li class="toctree-l2"><a class="reference internal" href="jaccard.html">Jaccard Similarity</a></li>
<li class="toctree-l2"><a class="reference internal" href="tuple_policy.html">Tuple Policy</a></li>
<li class="toctree-l2"><a class="reference internal" href="ks_test.html">Kolmogorov-Smirnov Test</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">Kernel Function</a><ul>
<li class="toctree-l3"><a class="reference internal" href="#datasketches.KernelFunction"><code class="docutils literal notranslate"><span class="pre">KernelFunction</span></code></a><ul>
<li class="toctree-l4"><a class="reference internal" href="#datasketches.KernelFunction.__call__"><code class="docutils literal notranslate"><span class="pre">KernelFunction.__call__()</span></code></a></li>
</ul>
</li>
<li class="toctree-l3"><a class="reference internal" href="#datasketches.GaussianKernel"><code class="docutils literal notranslate"><span class="pre">GaussianKernel</span></code></a></li>
</ul>
</li>
</ul>
</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">Helper Classes</a></li>
<li class="breadcrumb-item active">Kernel Function</li>
<li class="wy-breadcrumbs-aside">
<a href="../_sources/helper/kernel.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="kernel-function">
<h1>Kernel Function<a class="headerlink" href="#kernel-function" title="Link to this heading"></a></h1>
<p>A <a class="reference external" href="https://en.wikipedia.org/wiki/Positive-definite_kernel">kernel function</a> is a specific type of
mathematical funciton that is particularly useful in certain machine learning and pattern recognition
contexts. The <a class="reference internal" href="../vector/density_sketch.html#datasketches.density_sketch" title="datasketches.density_sketch"><code class="xref py py-class docutils literal notranslate"><span class="pre">density_sketch</span></code></a> performs approximate
<a class="reference external" href="https://en.wikipedia.org/wiki/Kernel_density_estimation">kernel density estimation</a> which, unsurprisingly,
relies on the use of such a kernel function.</p>
<p>The library provides an abstract base class <a class="reference internal" href="#datasketches.KernelFunction" title="datasketches.KernelFunction"><code class="xref py py-class docutils literal notranslate"><span class="pre">KernelFunction</span></code></a> and an example implementation of a
Gaussian (also known as a Radial Basis Function) kernel. Custom classes must override the base class
and provide a floating point value as a score indicating the similarity of two input vectors.</p>
<dl class="py class">
<dt class="sig sig-object py" id="datasketches.KernelFunction">
<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">KernelFunction</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.KernelFunction" title="Link to this definition"></a></dt>
<dd><p>A generic base class from which user-defined kernels must inherit.</p>
<dl class="py method">
<dt class="sig sig-object py" id="datasketches.KernelFunction.__call__">
<span class="sig-name descname"><span class="pre">__call__</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">a</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">object</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">b</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">object</span></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">float</span></span></span><a class="headerlink" href="#datasketches.KernelFunction.__call__" title="Link to this definition"></a></dt>
<dd><p>A method to evaluate a kernel with given inputs a and b.</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>a</strong> (<em>numpy array</em>) – An input vector</p></li>
<li><p><strong>b</strong> (<em>numpy array</em>) – An input vector</p></li>
</ul>
</dd>
<dt class="field-even">Returns<span class="colon">:</span></dt>
<dd class="field-even"><p>A vector similarity score</p>
</dd>
<dt class="field-odd">Return type<span class="colon">:</span></dt>
<dd class="field-odd"><p>float</p>
</dd>
</dl>
</dd></dl>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="datasketches.GaussianKernel">
<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">GaussianKernel</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">bandwidth</span></span><span class="p"><span class="pre">:</span></span><span class="w"> </span><span class="n"><span class="pre">float</span></span><span class="w"> </span><span class="o"><span class="pre">=</span></span><span class="w"> </span><span class="default_value"><span class="pre">1.0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#datasketches.GaussianKernel" title="Link to this definition"></a></dt>
<dd><p>Bases: <a class="reference internal" href="#datasketches.KernelFunction" title="_datasketches.KernelFunction"><code class="xref py py-class docutils literal notranslate"><span class="pre">KernelFunction</span></code></a></p>
<p>Implements a basic Gaussian kernel</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>bandwidth</strong> (<em>float</em>) – The kernel bandwidth, default 1.0</p>
</dd>
</dl>
</dd></dl>
</section>
</div>
</div>
<footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
<a href="ks_test.html" class="btn btn-neutral float-left" title="Kolmogorov-Smirnov Test" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</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>