---

title: Actor-critic Model


keywords: fastai
sidebar: home_sidebar

summary: "RL Actor-critic model framework."
description: "RL Actor-critic model framework."
nb_path: "nbs/models/actor_critic.ipynb"
---
<!--

#################################################
### THIS FILE WAS AUTOGENERATED! DO NOT EDIT! ###
#################################################
# file to edit: nbs/models/actor_critic.ipynb
# command to build the docs after a change: nbdev_build_docs

-->

<div class="container" id="notebook-container">
        
    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h2 id="Actor" class="doc_header"><code>class</code> <code>Actor</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/models/actor_critic.py#L11" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Actor</code>(<strong><code>embedded_state_size</code></strong>:<code>int</code>, <strong><code>action_weight_size</code></strong>:<code>int</code>, <strong><code>hidden_sizes</code></strong>:<code>Tuple</code>[<code>int</code>]) :: <code>Module</code></p>
</blockquote>
<p>Actor Network</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

<div class="output_wrapper">
<div class="output">

<div class="output_area">


<div class="output_markdown rendered_html output_subarea ">
<h2 id="Critic" class="doc_header"><code>class</code> <code>Critic</code><a href="https://github.com/RecoHut-Projects/recohut/tree/master/recohut/models/actor_critic.py#L42" class="source_link" style="float:right">[source]</a></h2><blockquote><p><code>Critic</code>(<strong><code>embedded_state_size</code></strong>:<code>int</code>, <strong><code>embedded_action_size</code></strong>:<code>int</code>, <strong><code>hidden_sizes</code></strong>:<code>Tuple</code>[<code>int</code>]) :: <code>Module</code></p>
</blockquote>
<p>Critic Network</p>

</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">embedded_state_size</span> <span class="o">=</span> <span class="mi">64</span>
<span class="n">embedded_action_size</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">actor_hidden_sizes</span> <span class="o">=</span> <span class="p">(</span><span class="mi">128</span><span class="p">,</span> <span class="mi">64</span><span class="p">)</span>
<span class="n">critic_hidden_sizes</span> <span class="o">=</span> <span class="p">(</span><span class="mi">32</span><span class="p">,</span> <span class="mi">16</span><span class="p">)</span>

<span class="n">actor</span> <span class="o">=</span> <span class="n">Actor</span><span class="p">(</span><span class="n">embedded_state_size</span><span class="o">=</span><span class="n">embedded_state_size</span><span class="p">,</span>
              <span class="n">action_weight_size</span><span class="o">=</span><span class="n">embedded_action_size</span><span class="p">,</span>
              <span class="n">hidden_sizes</span><span class="o">=</span><span class="n">actor_hidden_sizes</span><span class="p">)</span>
<span class="n">critic</span> <span class="o">=</span> <span class="n">Critic</span><span class="p">(</span><span class="n">embedded_state_size</span><span class="o">=</span><span class="n">embedded_state_size</span><span class="p">,</span>
                <span class="n">embedded_action_size</span><span class="o">=</span><span class="n">embedded_action_size</span><span class="p">,</span>
                <span class="n">hidden_sizes</span><span class="o">=</span><span class="n">critic_hidden_sizes</span><span class="p">)</span>
</pre></div>

    </div>
</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">torch</span><span class="o">.</span><span class="n">manual_seed</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">actor</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">embedded_state_size</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>tensor([[-0.1129, -0.0019,  0.0999, -0.0621,  0.0551],
        [-0.0445, -0.0425,  0.0677, -0.0397,  0.0003]],
       grad_fn=&lt;AddmmBackward0&gt;)</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

    {% raw %}
    
<div class="cell border-box-sizing code_cell rendered">
<div class="input">

<div class="inner_cell">
    <div class="input_area">
<div class=" highlight hl-ipython3"><pre><span></span><span class="n">torch</span><span class="o">.</span><span class="n">manual_seed</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="n">critic</span><span class="o">.</span><span class="n">forward</span><span class="p">(</span><span class="n">torch</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">embedded_state_size</span><span class="p">),</span><span class="n">torch</span><span class="o">.</span><span class="n">rand</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="n">embedded_action_size</span><span class="p">))</span>
</pre></div>

    </div>
</div>
</div>

<div class="output_wrapper">
<div class="output">

<div class="output_area">



<div class="output_text output_subarea output_execute_result">
<pre>tensor([[-0.1659],
        [-0.1432]], grad_fn=&lt;AddmmBackward0&gt;)</pre>
</div>

</div>

</div>
</div>

</div>
    {% endraw %}

</div>
 

