<blockquote>
<p>I think that std::vectorarma::mat* is a little bit awkward; could you possibly instead take the &gt;instantiated network as the input and extract/modify the parameters from there?</p>
</blockquote>

<p>There are some problems here<br>
1 : Neither softmax nor stackautoencoder can access the input data, but when you are finetuning the parameters, the input need to update frequently. Pass by pointer is a less intrusive solution I can think of by now(not reference because reference cannot take the reference of reference). We have to let the users access the input data if we want to pass in the instantiated network.</p>

<p>2 : The class softmaxRegression cannot  access parameters. However, about the parameters, pass by std::vector should be better, because I do not know when should I update the parameter, this should be done by another api after the whole training process finished.</p>

<p>3 : Pass by the instantiated network would make the implementation details a little bit complex(need to deal with compile time for loop, that means, we need TMP at here).</p>

<p>ex : <br>
    auto networkTuple = std::forward_as_tuple(sae1, sae2);<br>
    FineTuneFunction&lt;<br>
    decltype(networkTuple),<br>
    SoftmaxRegressionFunction,<br>
    SoftmaxFineTune<br>
    &gt; finetune(networkTuple, softmax);</p>

<blockquote>
<p>What does the function Deriv(arma::mat const&amp;, arma::mat&amp;) do? How is that different from Gradient()?</p>
</blockquote>

<p>The details is listed by UFLDL(<a href="http://deeplearning.stanford.edu/wiki/index.php/Fine-tuning_Stacked_AEs">http://deeplearning.stanford.edu/wiki/index.php/Fine-tuning_Stacked_AEs</a>)</p>

<p>Gradient() is the derivative related to the last layer of the finetune network(J of number 2)<br>
Deriv() will calculate the derivate of back propagation of neural network(f'(z) of number 3)</p>

<p>Example : </p>

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

    static void Deriv(arma::mat const &amp;input, arma::mat &amp;output)
    {
        output = input % (1 - input);
    }
};
</code></pre>

<p>If the last layer always should be softmax, then we could remove this template parameter.</p>

<blockquote>
<p>So this way, the EvaluateWithGradient() function would be optional, but when supplied it could <br>
accelerate the computation. What do you think of this idea?</p>
</blockquote>

<p>This could save one calculation, but you still need to recalculate the probabilities if you do not cache it when finetune(if you are using softmaxRegression as last layer), one calculation is done by Evaluate, one is Gradient, another one is finetune(when finding the last derivative term). Could we just let the SoftmaxRegression cache the probabilities and let the users access it(read only)?</p>

<pre><code>SoftmaxRegressionFunction
{
 public:
  //! Gets the probabilities.
  const arma::mat&amp; Probabilities() const { return probabilities; }
 private:
  //! Probability matrix
  arma::mat probabilities;
};
</code></pre>

<p>When you call the Evaluate function, rather than create a temporary variable, use the data member<br>
    probabilities. </p>

<p>When you call the Gradient function, do not recalculate, just reuse the calculated probabilities, this probabilities only depend on the training data and the weights(parameters), and the weights(parameters) would not update before you call the Gradient function, so it should be safe to cache it(unless there are some optimization algorithms would not call Evaluate before calling Gradient) I try and run the unit test, it works fine.</p>

<blockquote>
<p>I don't know if there are already any plans for fine tuning.</p>
</blockquote>

<p>I hope there are, this is a quite useful tool.</p>

<p>Thanks for your helps:).</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/issues/458#issuecomment-145789345">view it on GitHub</a>.<img alt="" height="1" src="https://github.com/notifications/beacon/AJ4bFO8AVYo-bf6oPpTLGzWapwif5i09ks5o44OKgaJpZM4GIjrs.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-145789345"></link>
  <meta itemprop="name" content="View Issue"></meta>
</div>
<meta itemprop="description" content="View this Issue on GitHub"></meta>
</div>