<p>I do some change on the api of FineTuneGradient, this api may provide better optimization codes</p>

<pre><code>class SoftmaxFineTune
{
 public:
  template&lt;typename T&gt;
  static void LastGradient(arma::mat const &amp;input,
                           arma::mat const &amp;weights,
                           T const &amp;model,
                           arma::mat &amp;gradient)
    {
        gradient = (weights.t() * model.Probabilities()) /
                static_cast&lt;double&gt;(input.n_cols);
        gradient = gradient % (input % (1 - input));
    }

    static void Gradient(arma::mat const &amp;input,
                         arma::mat const &amp;weight,
                         arma::mat const &amp;deriv,
                         arma::mat &amp;output)
    {
        output = (weight.t() * deriv) % (input % (1 - input));
    }
};
</code></pre>

<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/issues/458#issuecomment-146073692">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFBzuYXeoBowBuNxv_byJb_gMCSbRks5o5JSpgaJpZM4GIjrs.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/issues/458#issuecomment-146073692"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>