mirror of
https://github.com/tensorflow/haskell.git
synced 2024-12-26 19:49:46 +01:00
19 lines
29 KiB
HTML
19 lines
29 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>TensorFlow.Variable</title><link href="ocean.css" rel="stylesheet" type="text/css" title="Ocean" /><script src="haddock-util.js" type="text/javascript"></script><script src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script><script type="text/javascript">//<![CDATA[
|
||
|
window.onload = function () {pageLoad();setSynopsis("mini_TensorFlow-Variable.html");};
|
||
|
//]]>
|
||
|
</script></head><body><div id="package-header"><ul class="links" id="page-menu"><li><a href="src/TensorFlow.Variable.html">Source</a></li><li><a href="index.html">Contents</a></li><li><a href="doc-index.html">Index</a></li></ul><p class="caption">tensorflow-ops-0.1.0.0: Friendly layer around TensorFlow bindings.</p></div><div id="content"><div id="module-header"><table class="info"><tr><th>Safe Haskell</th><td>None</td></tr><tr><th>Language</th><td>Haskell2010</td></tr></table><p class="caption">TensorFlow.Variable</p></div><div id="description"><p class="caption">Description</p><div class="doc"><p>An implementation of ResourceHandle-based variables.</p><p>The main difference between this and <code><a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Ref">Ref</a></code>-based variables is
|
||
|
that reads are explicit, via the <code><a href="TensorFlow-Variable.html#v:readValue">readValue</a></code> op.</p><p>TODO: given that distinction, figure out a good story around
|
||
|
gradients and save/restore. Then, merge this module into
|
||
|
TensorFlow.Ops.</p></div></div><div id="synopsis"><p id="control.syn" class="caption expander" onclick="toggleSection('syn')">Synopsis</p><ul id="section.syn" class="hide" onclick="toggleSection('syn')"><li class="src short"><span class="keyword">data</span> <a href="#t:Variable">Variable</a> a</li><li class="src short"><a href="#v:variable">variable</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:variable-39-">variable'</a> :: <span class="keyword">forall</span> m a. (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:readValue">readValue</a> :: <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a => <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> <a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:Build">Build</a> a</li><li class="src short"><a href="#v:initializedValue">initializedValue</a> :: <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../base-4.9.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Value">Value</a> a)</li><li class="src short"><a href="#v:initializedVariable">initializedVariable</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:initializedVariable-39-">initializedVariable'</a> :: <span class="keyword">forall</span> a m v. (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:zeroInitializedVariable">zeroInitializedVariable</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a, <a href="../base-4.9.1.0/Prelude.html#t:Num">Num</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:zeroInitializedVariable-39-">zeroInitializedVariable'</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a, <a href="../base-4.9.1.0/Prelude.html#t:Num">Num</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a)</li><li class="src short"><a href="#v:assign">assign</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2
|
||
|
however, it may be CSE'd with other reads in the same context. The context can
|
||
|
be fixed by using <code><a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#v:render">render</a></code> along with (for example) <code><a href="../tensorflow-0.1.0.2/TensorFlow-ControlFlow.html#v:withControlDependencies">withControlDependencies</a></code>.
|
||
|
For example:</p><pre> runSession $ do
|
||
|
v <- variable []
|
||
|
a <- assign v 24
|
||
|
r <- withControlDependencies a $ render $ readValue v + 18
|
||
|
result <- run r
|
||
|
liftIO $ (42 :: Float) @=? unScalar result</pre></div></div><div class="top"><p class="src"><a id="v:initializedValue" class="def">initializedValue</a> :: <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../base-4.9.1.0/Data-Maybe.html#t:Maybe">Maybe</a> (<a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Value">Value</a> a) <a href="src/TensorFlow.Variable.html#initializedValue" class="link">Source</a> <a href="#v:initializedValue" class="selflink">#</a></p><div class="doc"><p>The initial value of a <code><a href="TensorFlow-Variable.html#t:Variable">Variable</a></code> created with <code><a href="TensorFlow-Variable.html#v:initializedVariable">initializedVariable</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:initializedVariable" class="def">initializedVariable</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a) <a href="src/TensorFlow.Variable.html#initializedVariable" class="link">Source</a> <a href="#v:initializedVariable" class="selflink">#</a></p><div class="doc"><p>Creates a variable initialized to the given value.
|
||
|
Initialization happens next time session runs.</p></div></div><div class="top"><p class="src"><a id="v:initializedVariable-39-" class="def">initializedVariable'</a> :: <span class="keyword">forall</span> a m v. (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a) <a href="src/TensorFlow.Variable.html#initializedVariable%27" class="link">Source</a> <a href="#v:initializedVariable-39-" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:zeroInitializedVariable" class="def">zeroInitializedVariable</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a, <a href="../base-4.9.1.0/Prelude.html#t:Num">Num</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a) <a href="src/TensorFlow.Variable.html#zeroInitializedVariable" class="link">Source</a> <a href="#v:zeroInitializedVariable" class="selflink">#</a></p><div class="doc"><p>Creates a zero-initialized variable with the given shape.</p></div></div><div class="top"><p class="src"><a id="v:zeroInitializedVariable-39-" class="def">zeroInitializedVariable'</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a, <a href="../base-4.9.1.0/Prelude.html#t:Num">Num</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:Shape">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable">Variable</a> a) <a href="src/TensorFlow.Variable.html#zeroInitializedVariable%27" class="link">Source</a> <a href="#v:zeroInitializedVariable-39-" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:assign" class="def">assign</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m <a href="../tensorflow-0.1.0.2/TensorFlow-Output.html#t:ControlNode">ControlNode</a> <a href="src/TensorFlow.Variable.html#assign" class="link">Source</a> <a href="#v:assign" class="selflink">#</a></p><div class="doc"><p>Sets the value of a variable.</p></div></div><div class="top"><p class="src"><a id="v:assign-39-" class="def">assign'</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a> -> <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m <a href="../tensorflow-0.1.0.2/TensorFlow-Output.html#t:ControlNode">ControlNode</a> <a href="src/TensorFlow.Variable.html#assign%27" class="link">Source</a> <a href="#v:assign-39-" class="selflink">#</a></p></div><div class="top"><p class="src"><a id="v:assignAdd" class="def">assignAdd</a> :: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:TensorType">TensorType</a> a) => <a href="TensorFlow-Variable.html#t:Variable">Variable</a> a -> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v a -> m <a href="../tensorflow-0.1.0.2/TensorFlow-Output.html
|
||
|
m_t <- beta1 * m_{t-1} + (1 - beta1) * g_t
|
||
|
v_t <- beta2 * v_{t-1} + (1 - beta2) * g_t * g_t
|
||
|
variable <- variable - lr_t * m_t / (sqrt(v_t) + epsilon)</p></div></div><div class="top"><p class="src"><a id="v:resourceApplyAdam-39-" class="def">resourceApplyAdam'</a> <a href="src/TensorFlow.Variable.html#resourceApplyAdam%27" class="link">Source</a> <a href="#v:resourceApplyAdam-39-" class="selflink">#</a></p><div class="subs arguments"><p class="caption">Arguments</p><table><tr><td class="src">:: (<a href="../tensorflow-0.1.0.2/TensorFlow-Build.html#t:MonadBuild">MonadBuild</a> m, <a href="../tensorflow-0.1.0.2/TensorFlow-Types.html#t:OneOf">OneOf</a> '[<a href="../base-4.9.1.0/Data-Complex.html#t:Complex">Complex</a> <a href="../base-4.9.1.0/Prelude.html#t:Double">Double</a>, <a href="../base-4.9.1.0/Data-Complex.html#t:Complex">Complex</a> <a href="../base-4.9.1.0/Prelude.html#t:Float">Float</a>, <a href="../base-4.9.1.0/Data-Int.html#t:Int16">Int16</a>, <a href="../base-4.9.1.0/Data-Int.html#t:Int32">Int32</a>, <a href="../base-4.9.1.0/Data-Int.html#t:Int64">Int64</a>, <a href="../base-4.9.1.0/Data-Int.html#t:Int8">Int8</a>, <a href="../base-4.9.1.0/Data-Word.html#t:Word16">Word16</a>, <a href="../base-4.9.1.0/Data-Word.html#t:Word8">Word8</a>, <a href="../base-4.9.1.0/Prelude.html#t:Double">Double</a>, <a href="../base-4.9.1.0/Prelude.html#t:Float">Float</a>] t)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="../tensorflow-0.1.0.2/TensorFlow-BuildOp.html#t:OpParams">OpParams</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="TensorFlow-Variable.html#t:Variable">Variable</a> t</td><td class="doc"><p><strong>var</strong>: Should be from a Variable().</p></td></tr><tr><td class="src">-> <a href="TensorFlow-Variable.html#t:Variable">Variable</a> t</td><td class="doc"><p><strong>m</strong>: Should be from a Variable().</p></td></tr><tr><td class="src">-> <a href="TensorFlow-Variable.html#t:Variable">Variable</a> t</td><td class="doc"><p><strong>v</strong>: Should be from a Variable().</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v1 t</td><td class="doc"><p><strong>beta1_power</strong>: Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v2 t</td><td class="doc"><p><strong>beta2_power</strong>: Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v3 t</td><td class="doc"><p><strong>lr</strong>: Scaling factor. Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v4 t</td><td class="doc"><p><strong>beta1</strong>: Momentum factor. Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v5 t</td><td class="doc"><p><strong>beta2</strong>: Momentum factor. Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v6 t</td><td class="doc"><p><strong>epsilon</strong>: Ridge term. Must be a scalar.</p></td></tr><tr><td class="src">-> <a href="../tensorflow-0.1.0.2/TensorFlow-Tensor.html#t:Tensor">Tensor</a> v7 t</td><td class="doc"><p><strong>grad</strong>: The gradient.</p></td></tr><tr><td class="src">-> m <a href="../tensorflow-0.1.0.2/TensorFlow-Output.html#t:ControlNode">ControlNode</a></td><td class="doc empty"> </td></tr></table></div></div></div></div><div id="footer"><p>Produced by <a href="http://www.haskell.org/haddock/">Haddock</a> version 2.17.3</p></div></body></html>
|