<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>model module &mdash; LEAF 0.1 documentation</title>
  

  
  
  
  

  

  
  
    

  

  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/customheader.css" type="text/css" />
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="server module" href="server.html" />
    <link rel="prev" title="metrics package" href="metrics.html" /> 

  
  <script src="../_static/js/modernizr.min.js"></script>

</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"> LEAF
          

          
          </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" />
    <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="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Getting Started</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../install/get_leaf.html">Installation and Contribution</a></li>
</ul>
<p class="caption"><span class="caption-text">User Guide</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../tutorials/index.html">General Examples</a></li>
</ul>
<p class="caption"><span class="caption-text">API Documentation</span></p>
<ul class="current">
<li class="toctree-l1 current"><a class="reference internal" href="modules.html">models</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="baseline_constants.html">baseline_constants module</a></li>
<li class="toctree-l2"><a class="reference internal" href="client.html">client module</a></li>
<li class="toctree-l2"><a class="reference internal" href="main.html">main module</a></li>
<li class="toctree-l2"><a class="reference internal" href="metrics.html">metrics package</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">model module</a></li>
<li class="toctree-l2"><a class="reference internal" href="server.html">server module</a></li>
<li class="toctree-l2"><a class="reference internal" href="utils.html">utils package</a></li>
</ul>
</li>
</ul>
<p class="caption"><span class="caption-text">Additional Information</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../contact.html">Contact</a></li>
<li class="toctree-l1"><a class="reference internal" href="../citations.html">Citing LEAF</a></li>
</ul>

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

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../index.html">LEAF</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../index.html">Docs</a> &raquo;</li>
        
          <li><a href="modules.html">models</a> &raquo;</li>
        
      <li>model module</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="../_sources/autodoc/model.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">
            
  <div class="section" id="module-model">
<span id="model-module"></span><h1>model module<a class="headerlink" href="#module-model" title="Permalink to this headline">¶</a></h1>
<p>Interfaces for ClientModel and ServerModel.</p>
<dl class="class">
<dt id="model.Model">
<em class="property">class </em><code class="descclassname">model.</code><code class="descname">Model</code><span class="sig-paren">(</span><em>lr</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/abc.html#abc.ABC" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">abc.ABC</span></code></a></p>
<dl class="method">
<dt id="model.Model.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.close"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.close" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="model.Model.create_model">
<code class="descname">create_model</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.create_model"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.create_model" title="Permalink to this definition">¶</a></dt>
<dd><p>Creates the model for the task.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Returns:</th><td class="field-body">features: A placeholder for the samples' features.
labels: A placeholder for the samples' labels.
train_op: A Tensorflow operation that, when run with the features and<blockquote>
<div>the labels, trains the model.</div></blockquote>
<dl class="docutils">
<dt>eval_metric_ops: A Tensorflow operation that, when run with features and labels,</dt>
<dd>returns the accuracy of the model.</dd>
</dl>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Return type:</th><td class="field-body">A 4-tuple consisting of</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="model.Model.optimizer">
<code class="descname">optimizer</code><a class="headerlink" href="#model.Model.optimizer" title="Permalink to this definition">¶</a></dt>
<dd><p>Optimizer to be used by the model.</p>
</dd></dl>

<dl class="method">
<dt id="model.Model.process_x">
<code class="descname">process_x</code><span class="sig-paren">(</span><em>raw_x_batch</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.process_x"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.process_x" title="Permalink to this definition">¶</a></dt>
<dd><p>Pre-processes each batch of features before being fed to the model.</p>
</dd></dl>

<dl class="method">
<dt id="model.Model.process_y">
<code class="descname">process_y</code><span class="sig-paren">(</span><em>raw_y_batch</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.process_y"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.process_y" title="Permalink to this definition">¶</a></dt>
<dd><p>Pre-processes each batch of labels before being fed to the model.</p>
</dd></dl>

<dl class="method">
<dt id="model.Model.test">
<code class="descname">test</code><span class="sig-paren">(</span><em>data</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.test"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.test" title="Permalink to this definition">¶</a></dt>
<dd><p>Tests the current model on the given data.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>data</strong> – dict of the form {'x': [list], 'y': [list]}</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body">dict of metrics that will be recorded by the simulation.</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="model.Model.train">
<code class="descname">train</code><span class="sig-paren">(</span><em>data</em>, <em>num_epochs=1</em>, <em>batch_size=10</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#Model.train"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.Model.train" title="Permalink to this definition">¶</a></dt>
<dd><p>Trains the client model.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><strong>data</strong> – Dict of the form {'x': [list], 'y': [list]}.</li>
<li><strong>num_epochs</strong> – Number of epochs to train.</li>
<li><strong>batch_size</strong> – Size of training batches.</li>
</ul>
</td>
</tr>
<tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><p class="first"><p>Number of FLOPs computed while training given data
update: List of np.ndarray weights, with each weight array</p>
<blockquote>
<div><p>corresponding to a variable in the resulting graph</p>
</div></blockquote>
</p>
</td>
</tr>
<tr class="field-odd field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">comp</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="model.ServerModel">
<em class="property">class </em><code class="descclassname">model.</code><code class="descname">ServerModel</code><span class="sig-paren">(</span><em>model</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#ServerModel"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.ServerModel" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.7)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<dl class="method">
<dt id="model.ServerModel.close">
<code class="descname">close</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#ServerModel.close"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.ServerModel.close" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="attribute">
<dt id="model.ServerModel.cur_model">
<code class="descname">cur_model</code><a class="headerlink" href="#model.ServerModel.cur_model" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="model.ServerModel.save">
<code class="descname">save</code><span class="sig-paren">(</span><em>path='checkpoints/model.ckpt'</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#ServerModel.save"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.ServerModel.save" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="model.ServerModel.send_to">
<code class="descname">send_to</code><span class="sig-paren">(</span><em>clients</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#ServerModel.send_to"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.ServerModel.send_to" title="Permalink to this definition">¶</a></dt>
<dd><p>Copies server model variables to each of the given clients</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>clients</strong> – list of Client objects</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="attribute">
<dt id="model.ServerModel.size">
<code class="descname">size</code><a class="headerlink" href="#model.ServerModel.size" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="model.ServerModel.update">
<code class="descname">update</code><span class="sig-paren">(</span><em>updates</em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/model.html#ServerModel.update"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#model.ServerModel.update" title="Permalink to this definition">¶</a></dt>
<dd><p>Updates server model using given client updates.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Parameters:</th><td class="field-body"><strong>updates</strong> – list of (num_samples, update), where num_samples is the
number of training samples corresponding to the update, and update
is a list of variable weights</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="server.html" class="btn btn-neutral float-right" title="server module" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="metrics.html" class="btn btn-neutral" title="metrics package" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2019, Talwalkar Lab

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    
    
      <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
        <script type="text/javascript" src="../_static/jquery.js"></script>
        <script type="text/javascript" src="../_static/underscore.js"></script>
        <script type="text/javascript" src="../_static/doctools.js"></script>
    

  

  <script type="text/javascript" src="../_static/js/theme.js"></script>

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

</body>
</html>