mirror of
https://github.com/tensorflow/haskell.git
synced 2024-12-02 15:59:45 +01:00
16 lines
36 KiB
HTML
16 lines
36 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" /><meta name="viewport" content="width=device-width, initial-scale=1" /><title>TensorFlow.Variable</title><link href="linuwial.css" rel="stylesheet" type="text/css" title="Linuwial" /><link rel="stylesheet" type="text/css" href="quick-jump.css" /><link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=PT+Sans:400,400i,700" /><script src="haddock-bundle.min.js" async="async" type="text/javascript"></script><script type="text/x-mathjax-config">MathJax.Hub.Config({ tex2jax: { processClass: "mathjax", ignoreClass: ".*" } });</script><script src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML" type="text/javascript"></script></head><body><div id="package-header"><span class="caption">tensorflow-ops-0.3.0.0: Friendly layer around TensorFlow bindings.</span><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></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.3.0.0/TensorFlow-Tensor.html#t:Ref" title="TensorFlow.Tensor">Ref</a></code>-based variables is
|
||
|
that reads are explicit, via the <code><a href="TensorFlow-Variable.html#v:readValue" title="TensorFlow.Variable">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"><details id="syn"><summary>Synopsis</summary><ul class="details-toggle" data-details-id="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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:Shape" title="TensorFlow.Types">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a> -> <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:Shape" title="TensorFlow.Types">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a)</li><li class="src short"><a href="#v:readValue">readValue</a> :: <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a => <a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a -> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> <a href="../tensorflow-0.3.0.0/TensorFlow-Build.html#t:Build" title="TensorFlow.Build">Build</a> a</li><li class="src short"><a href="#v:initializedValue">initializedValue</a> :: <a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a -> <a href="../base-4.13.0.0/Data-Maybe.html#t:Maybe" title="Data.Maybe">Maybe</a> (<a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Value" title="TensorFlow.Tensor">Value</a> a)</li><li class="src short"><a href="#v:initializedVariable">initializedVariable</a> :: (<a href="../tensorflow-0.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a> -> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a)</li><li class="src short"><a href="#v:zeroInitializedVariable">zeroInitializedVariable</a> :: (<a href="../tensorflow-0.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a, <a href="../base-4.13.0.0/Prelude.html#t:Num" title="Prelude">Num</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:Shape" title="TensorFlow.Types">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a)</li>
|
||
|
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.3.0.0/TensorFlow-Tensor.html#v:render" title="TensorFlow.Tensor">render</a></code> along with (for example) <code><a href="../tensorflow-0.3.0.0/TensorFlow-ControlFlow.html#v:withControlDependencies" title="TensorFlow.ControlFlow">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" title="TensorFlow.Variable">Variable</a> a -> <a href="../base-4.13.0.0/Data-Maybe.html#t:Maybe" title="Data.Maybe">Maybe</a> (<a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Value" title="TensorFlow.Tensor">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" title="TensorFlow.Variable">Variable</a></code> created with <code><a href="TensorFlow-Variable.html#v:initializedVariable" title="TensorFlow.Variable">initializedVariable</a></code>.</p></div></div><div class="top"><p class="src"><a id="v:initializedVariable" class="def">initializedVariable</a> :: (<a href="../tensorflow-0.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a> -> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a, <a href="../base-4.13.0.0/Prelude.html#t:Num" title="Prelude">Num</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:Shape" title="TensorFlow.Types">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a, <a href="../base-4.13.0.0/Prelude.html#t:Num" title="Prelude">Num</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a> -> <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:Shape" title="TensorFlow.Types">Shape</a> -> m (<a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a -> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m <a href="../tensorflow-0.3.0.0/TensorFlow-Output.html#t:ControlNode" title="TensorFlow.Output">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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:TensorType" title="TensorFlow.Types">TensorType</a> a) => <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a> -> <a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.Variable">Variable</a> a -> <a href="../tensorflow-0.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.Tensor">Tensor</a> v a -> m <a href="../tensorfl
|
||
|
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.3.0.0/TensorFlow-Build.html#t:MonadBuild" title="TensorFlow.Build">MonadBuild</a> m, <a href="../tensorflow-0.3.0.0/TensorFlow-Types.html#t:OneOf" title="TensorFlow.Types">OneOf</a> '[<a href="../base-4.13.0.0/Data-Complex.html#t:Complex" title="Data.Complex">Complex</a> <a href="../base-4.13.0.0/Prelude.html#t:Double" title="Prelude">Double</a>, <a href="../base-4.13.0.0/Data-Complex.html#t:Complex" title="Data.Complex">Complex</a> <a href="../base-4.13.0.0/Prelude.html#t:Float" title="Prelude">Float</a>, <a href="../base-4.13.0.0/Data-Int.html#t:Int16" title="Data.Int">Int16</a>, <a href="../base-4.13.0.0/Data-Int.html#t:Int32" title="Data.Int">Int32</a>, <a href="../base-4.13.0.0/Data-Int.html#t:Int64" title="Data.Int">Int64</a>, <a href="../base-4.13.0.0/Data-Int.html#t:Int8" title="Data.Int">Int8</a>, <a href="../base-4.13.0.0/Data-Word.html#t:Word16" title="Data.Word">Word16</a>, <a href="../base-4.13.0.0/Data-Word.html#t:Word8" title="Data.Word">Word8</a>, <a href="../base-4.13.0.0/Prelude.html#t:Double" title="Prelude">Double</a>, <a href="../base-4.13.0.0/Prelude.html#t:Float" title="Prelude">Float</a>] t)</td><td class="doc empty"> </td></tr><tr><td class="src">=> <a href="../tensorflow-0.3.0.0/TensorFlow-BuildOp.html#t:OpParams" title="TensorFlow.BuildOp">OpParams</a></td><td class="doc empty"> </td></tr><tr><td class="src">-> <a href="TensorFlow-Variable.html#t:Variable" title="TensorFlow.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" title="TensorFlow.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" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Tensor.html#t:Tensor" title="TensorFlow.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.3.0.0/TensorFlow-Output.html#t:ControlNode" title="TensorFlow.Output">ControlNode</a></td><td class="doc empty">&nb
|