<p>The Error function of the performance function need the network parameters,because the SparseCost need to access the Weights and RhoCap</p>

<p>The FFN take the copy of the network but not the reference of it, so it is no use to use the pointer to point to the weights and RhoCap of the network</p>

<pre><code>  //in this case, input can get from the network too
  double Error(const DataType &amp;target, const DataType &amp;error, const Network &amp;network)
  {
    // Calculate squared L2-norms of w1 and w2.
    const double wL2SquaredNorm =
        arma::accu(std::get&lt;0&gt;(network).Weights() % std::get&lt;0&gt;(network).Weights()) +
        arma::accu(std::get&lt;3&gt;(network).Weights() % std::get&lt;3&gt;(network).Weights());    

    const double sumOfSquaresError =
        0.5 * arma::accu(error % error) / target.n_cols;
    const double weightDecay = 0.5 * lambda * wL2SquaredNorm;
    const double klDivergence =
        beta * arma::accu(rho * arma::trunc_log(rho / std::get&lt;0&gt;(network).RhoCap()) + (1 - rho) *
                          arma::trunc_log((1 - rho) / (1 - std::get&lt;0&gt;(network).RhoCap())));    

    // The cost is the sum of the terms calculated above.
    return sumOfSquaresError + weightDecay + klDivergence;
  }
</code></pre>

<p>If you agree with it, I would make the necessary changes.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br>Reply to this email directly or <a href="https://github.com/mlpack/mlpack/pull/451#issuecomment-164266642">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFC6tXTZIB-SvYflCDPUcW2yD8CT8ks5pPX8LgaJpZM4GAqt4.gif" width="1" /></p>
<div itemscope itemtype="http://schema.org/EmailMessage">
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
  <link itemprop="url" href="https://github.com/mlpack/mlpack/pull/451#issuecomment-164266642"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>