-
Notifications
You must be signed in to change notification settings - Fork 1
/
solver.html
16 lines (16 loc) · 10.5 KB
/
solver.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8" /><title>Solvers — PyMatting 1.1.10 documentation</title><link rel="stylesheet" href="/katex.min.css"><link rel="stylesheet" href="/style.css"><script src="/katex.min.js"></script></head><body><div class="sidebar"><div class="logo"><a href="/" class="sidebarlink"><img src="/figures/lemur_small.png" width="50px"></a><a href="/" class="logotext">PyMatting</a></div><div class="sidebarcontents">CONTENTS</div><ul><li><a href="/index.html" class="sidebarlink">PyMatting</a></li><li class="sidebarlink"><a href="/api.html" class="sidebarlink">API Reference</a><br><ul><li><a href="/alpha.html" class="sidebarlink">Alpha Estimation</a></li><li><a href="/cutout.html" class="sidebarlink">Cutout Function</a></li><li><a href="/foreground.html" class="sidebarlink">Foreground Estimation</a></li><li><a href="/laplacian.html" class="sidebarlink">Matting Laplacians</a></li><li><a href="/preconditioner.html" class="sidebarlink">Preconditioners</a></li><li><a href="/solver.html" class="sidebarlink currentpage">Solvers</a></li><li><a href="/util.html" class="sidebarlink">Utility Functions</a></li></ul></li><li><a href="/examples.html" class="sidebarlink">Examples</a></li><li><a href="/benchmarks.html" class="sidebarlink">Benchmarks</a></li><li><a href="/references.html" class="sidebarlink">Biblography</a></li><li><a href="https://pypi.org/project/PyMatting/" class="sidebarlink">PyPI</a></li><li><a href="https://www.github.com/pymatting/pymatting" class="sidebarlink">GitHub</a></li></ul></div><div class="middle"><h1>Solvers</h1><div><div class="function"><div id="cg"><a href="https://github.com/pymatting/pymatting/blob/master/pymatting/solver/cg.py#L4-L117"><img src="/figures/github-mark.svg" title="Function definition on GitHub" class="github-icon"></a><h3 class="functionname">pymatting.cg</h3><a href="#cg" title="Permalink to this definition" class="functionanchorlink"> 🔗</a></div><div class="signature"><h4>Signature</h4><div class="signature"><div class="codeblock"><span class=name>cg</span><span class=operator>(</span><span class=space>
</span><span class=name>A</span><span class=operator>,</span><span class=space>
</span><span class=name>b</span><span class=operator>,</span><span class=space>
</span><span class=name>x0</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>atol</span><span class=operator>=</span><span class=number>0.0</span><span class=operator>,</span><span class=space>
</span><span class=name>rtol</span><span class=operator>=</span><span class=number>1e-7</span><span class=operator>,</span><span class=space>
</span><span class=name>maxiter</span><span class=operator>=</span><span class=number>10000</span><span class=operator>,</span><span class=space>
</span><span class=name>callback</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>M</span><span class=operator>=</span><span class=keyword>None</span><span class=operator>,</span><span class=space>
</span><span class=name>reorthogonalize</span><span class=operator>=</span><span class=keyword>False</span><span class=operator>)</span></div></div></div><h4>Function Description</h4><div class="textblock"><span class="text">Solves a system of linear equations </span><span class="inline_math">\(Ax=b\)</span><span class="text"> using conjugate gradient descent </span><span class="citation"><a href="/references.html#HS52">[HS52]</a></span></div><h4>Parameters</h4><ul><li class="parameteritem"><span class="parameter">A</span> (<i>scipy.sparse.csr_matrix</i>)<ul><div class="parameterdescription"><span class="text">Square matrix</span></div></ul></li><li class="parameteritem"><span class="parameter">b</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Vector describing the right-hand side of the system</span></div></ul></li><li class="parameteritem"><span class="parameter">x0</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Initialization, if </span><span class="inline_code"><span class="codeinline"><span class=keyword>None</span></span></span><span class="text"> then </span><span class="inline_code"><span class="codeinline"><span class=name>x</span><span class=operator>=</span><span class=name>np</span><span class=operator>.</span><span class=name>zeros_like</span><span class=operator>(</span><span class=name>b</span><span class=operator>)</span></span></span></div></ul></li><li class="parameteritem"><span class="parameter">atol</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Absolute tolerance. The loop terminates if the </span><span class="inline_math">\(||r||\)</span><span class="text"> is smaller than </span><span class="inline_code"><span class="codeinline"><span class=name>atol</span></span></span><span class="text">, where </span><span class="inline_math">\(r\)</span><span class="text"> denotes the residual of the current iterate.</span></div></ul></li><li class="parameteritem"><span class="parameter">rtol</span> (<i>float</i>)<ul><div class="parameterdescription"><span class="text">Relative tolerance. The loop terminates if </span><span class="inline_math">\({||r||}/{||b||}\)</span><span class="text"> is smaller than </span><span class="inline_code"><span class="codeinline"><span class=name>rtol</span></span></span><span class="text">, where </span><span class="inline_math">\(r\)</span><span class="text"> denotes the residual of the current iterate.</span></div></ul></li><li class="parameteritem"><span class="parameter">callback</span> (<i>function</i>)<ul><div class="parameterdescription"><span class="text">Function </span><span class="inline_code"><span class="codeinline"><span class=name>callback</span><span class=operator>(</span><span class=name>A</span><span class=operator>,</span><span class=space> </span><span class=name>x</span><span class=operator>,</span><span class=space> </span><span class=name>b</span><span class=operator>,</span><span class=space> </span><span class=name>norm_b</span><span class=operator>,</span><span class=space> </span><span class=name>r</span><span class=operator>,</span><span class=space> </span><span class=name>norm_r</span><span class=operator>)</span></span></span><span class="text"> called after each iteration, defaults to </span><span class="inline_code"><span class="codeinline"><span class=keyword>None</span></span></span></div></ul></li><li class="parameteritem"><span class="parameter">M</span> (<i>function or scipy.sparse.csr_matrix</i>)<ul><div class="parameterdescription"><span class="text">Function that applies the preconditioner to a vector. Alternatively, </span><span class="inline_code"><span class="codeinline"><span class=name>M</span></span></span><span class="text"> can be a matrix describing the precondioner.</span></div></ul></li><li class="parameteritem"><span class="parameter">reorthogonalize</span> (<i>boolean</i>)<ul><div class="parameterdescription"><span class="text">Whether to apply reorthogonalization of the residuals after each update, defaults to </span><span class="inline_code"><span class="codeinline"><span class=keyword>False</span></span></span></div></ul></li></ul><h4>Returns</h4><ul><li class="parameteritem"><span class="parameter">x</span> (<i>numpy.ndarray</i>)<ul><div class="parameterdescription"><span class="text">Solution of the system</span></div></ul></li></ul><div class="block"><h4>Example</h4><div class="code_block"><div class="codeblock"><span class=indentation>>>> </span><span class=keyword>from</span><span class=space> </span><span class=name>pymatting</span><span class=space> </span><span class=keyword>import</span><span class=space> </span><span class=operator>*</span><span class=space>
</span><span class=indentation>>>> </span><span class=keyword>import</span><span class=space> </span><span class=name>numpy</span><span class=space> </span><span class=keyword>as</span><span class=space> </span><span class=name>np</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>A</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>np</span><span class=operator>.</span><span class=name>array</span><span class=operator>(</span><span class=operator>[</span><span class=operator>[</span><span class=number>3.0</span><span class=operator>,</span><span class=space> </span><span class=number>1.0</span><span class=operator>]</span><span class=operator>,</span><span class=space> </span><span class=operator>[</span><span class=number>1.0</span><span class=operator>,</span><span class=space> </span><span class=number>2.0</span><span class=operator>]</span><span class=operator>]</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>M</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>jacobi</span><span class=operator>(</span><span class=name>A</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>b</span><span class=space> </span><span class=operator>=</span><span class=space> </span><span class=name>np</span><span class=operator>.</span><span class=name>array</span><span class=operator>(</span><span class=operator>[</span><span class=number>4.0</span><span class=operator>,</span><span class=space> </span><span class=number>3.0</span><span class=operator>]</span><span class=operator>)</span><span class=space>
</span><span class=indentation>>>> </span><span class=name>cg</span><span class=operator>(</span><span class=name>A</span><span class=operator>,</span><span class=space> </span><span class=name>b</span><span class=operator>,</span><span class=space> </span><span class=name>M</span><span class=operator>=</span><span class=name>M</span><span class=operator>)</span><span class=space>
</span><span class=name>array</span><span class=operator>(</span><span class=operator>[</span><span class=number>1</span><span class=operator>.</span><span class=operator>,</span><span class=space> </span><span class=number>1</span><span class=operator>.</span><span class=operator>]</span><span class=operator>)</span></div></div></div></div></div><footer>© Copyright 2023, Thomas Germer, Tobias Uelwer, Stefan Conrad, Stefan Harmeling</footer></div><script src="/auto-render.min.js" onload="renderMathInElement(document.body)"></script></body></html>