<p>Ok, find out the problem, we need a new "LinearLayer" which customize for the SparseAutoencoder, the problem is this part</p>

<pre><code>arma::mat klDivGrad = beta * (-(rho / rhoCap) + (1 - rho) / (1 - rhoCap));
klDivGrad.elem(arma::find_nonfinite(klDivGrad)).zeros();
diff2 = parameters.submat(l1, 0, l3 - 1, l2 - 1) * delOut +
          arma::repmat(klDivGrad, 1, data.n_cols);
arma::mat delHid;
hiddenLayerFunc.Backward(hiddenLayer, diff2, delHid);
</code></pre>

<p>We would need to have do some special calculation if this is sparse autoencoder, first we need the rho, second we need the rhoCap from the performance function, other parts are done by FNN already(please correct me if I am wrong). Good news are we do not need to modify the codes ann.</p>

<pre><code>LinearLayer&lt;RMSPROP, RandomInitialization&gt;
        hiddenLayer(visibleSize, hiddenSize, rho, {-range, range});  
</code></pre>

<p>The performance function should be able to accept the reference of RhoCap of hiddenLayer</p>

<pre><code>SparseErrorFunction(hiddenLayer.Weights(), outputLayer.Weights(), hiddenLayer.RhoCap(), 
                    beta, lambda)
</code></pre>

<p>Any suggestion?</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-162158379">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFEZZPWe-eSld55PmhHrfRRmrq9rvks5pMotSgaJpZM4GAqt4.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-162158379"></link>
  <meta itemprop="name" content="View Pull Request"></meta>
</div>
<meta itemprop="description" content="View this Pull Request on GitHub"></meta>
</div>