Update documentation with the changes.

Unify changes with test functions
This commit is contained in:
Shikhar Bhardwaj
2017-08-16 00:43:32 +05:30
parent db94857626
commit a4bfb4f096
4 changed files with 11 additions and 9 deletions
+5 -3
View File
@@ -82,10 +82,12 @@ To evaluate the loss function at the given coordinates, same as the
\c FunctionType interface.
@code
void FeatureGradient(const arma::mat& coordinates, const size_t j, double& gradient);
void FeatureGradient(const arma::mat& coordinates, const size_t j, arma::sp_mat& gradient);
@endcode
To evaluate the gradient at the given coordinates, where \c gradient is an
out-param for the required gradient. The out-param is a scalar value, for
storing the gradient of the jth feature.
out-param for the required gradient. The out-param is a sparse matrix(with
dimensions equal to the decision variable), for storing the gradient of the
jth feature. The \c gradient matrix is supposed to be non-zero in the jth
column, which contains the relavant partial gradient.
*/
@@ -67,7 +67,7 @@ class SparseTestFunction
const size_t i,
arma::sp_mat& gradient) const
{
gradient = arma::sp_mat(1, coordinates.n_cols);
gradient.zeros(coordinates.size());
gradient[i] = 2 * coordinates[i] + bi[i];
}
@@ -76,8 +76,8 @@ class SparseTestFunction
const size_t j,
arma::sp_mat& gradient) const
{
gradient.set_size(1);
gradient[0] = 2 * coordinates[j] + bi[j];
gradient.zeros(coordinates.size());
gradient[j] = 2 * coordinates[j] + bi[j];
}
private:
+1 -1
View File
@@ -53,7 +53,7 @@ double SCD<DescentPolicyType>::Optimize(ResolvableFunctionType& function,
function.FeatureGradient(iterate, featureIdx, gradient);
// Update the decision variable with the partial gradient.
iterate.col(featureIdx) -= stepSize * gradient;
iterate -= stepSize * gradient;
// Check for convergence.
if (i % updateInterval == 0)
+2 -2
View File
@@ -20,8 +20,8 @@
#include "test_tools.hpp"
using namespace std;
using namespace arma;
using namespace mlpack;
using namespace mlpack::math;
using namespace mlpack::optimization;
using namespace mlpack::optimization::test;
using namespace mlpack::regression;
@@ -135,7 +135,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFeatureGradientTest)
// Create random class labels.
arma::Row<size_t> labels(points);
for (size_t i = 0; i < points; i++)
labels(i) = math::RandInt(0, numClasses);
labels(i) = RandInt(0, numClasses);
// 2 objects for 2 terms in the cost function. Each term contributes towards
// the gradient and thus need to be checked independently.