Update documentation to rename FeatureGradient -> PartialGradient
This commit is contained in:
@@ -11,7 +11,7 @@ algorithm.
|
||||
The \c FunctionType template parameter required by the Optimizer class can have
|
||||
additional requirements imposed on it, depending on the type of optimizer used.
|
||||
|
||||
@section Interface requirements
|
||||
@section requirements Interface requirements
|
||||
|
||||
The most basic requirements for the \c FunctionType parameter are the
|
||||
implementations of two public member functions, with the following interface
|
||||
|
||||
@@ -72,7 +72,7 @@ class SparseTestFunction
|
||||
}
|
||||
|
||||
//! Evaluate the gradient of a feature function.
|
||||
void FeatureGradient(const arma::mat& coordinates,
|
||||
void PartialGradient(const arma::mat& coordinates,
|
||||
const size_t j,
|
||||
arma::sp_mat& gradient) const
|
||||
{
|
||||
|
||||
@@ -58,7 +58,7 @@ class GreedyDescent
|
||||
{
|
||||
arma::sp_mat fGrad;
|
||||
|
||||
function.FeatureGradient(iterate, i, fGrad);
|
||||
function.PartialGradient(iterate, i, fGrad);
|
||||
|
||||
double descent = arma::accu(fGrad);
|
||||
if (descent > bestDescent)
|
||||
|
||||
@@ -34,13 +34,13 @@ namespace optimization {
|
||||
*
|
||||
* size_t NumFeatures();
|
||||
* double Evaluate(const arma::mat& coordinates);
|
||||
* void FeatureGradient(const arma::mat& coordinates,
|
||||
* void PartialGradient(const arma::mat& coordinates,
|
||||
* const size_t j,
|
||||
* arma::sp_mat& gradient);
|
||||
*
|
||||
* NumFeatures() should return the number of features in the decision variable.
|
||||
* Evaluate gives the value of the loss function at the current decision
|
||||
* variable and FeatureGradient is used to evaluate the partial gradient with
|
||||
* variable and PartialGradient is used to evaluate the partial gradient with
|
||||
* respect to the jth feature.
|
||||
*
|
||||
* @tparam ResolvableFunctionType A function whose partial gradients with
|
||||
|
||||
@@ -50,7 +50,7 @@ double SCD<DescentPolicyType>::Optimize(ResolvableFunctionType& function,
|
||||
size_t featureIdx = descentPolicy.DescentFeature(i, iterate, function);
|
||||
|
||||
// Get the partial gradient with respect to this feature.
|
||||
function.FeatureGradient(iterate, featureIdx, gradient);
|
||||
function.PartialGradient(iterate, featureIdx, gradient);
|
||||
|
||||
// Update the decision variable with the partial gradient.
|
||||
iterate.col(featureIdx) -= stepSize * gradient.col(featureIdx);
|
||||
|
||||
@@ -118,7 +118,7 @@ class LogisticRegressionFunction
|
||||
* be computed.
|
||||
* @param gradient Sparse matrix to output gradient into.
|
||||
*/
|
||||
void FeatureGradient(const arma::mat& parameters,
|
||||
void PartialGradient(const arma::mat& parameters,
|
||||
const size_t j,
|
||||
arma::sp_mat& gradient) const;
|
||||
|
||||
|
||||
@@ -177,7 +177,7 @@ void LogisticRegressionFunction<MatType>::Gradient(
|
||||
* function with respect to the individual features in the parameter.
|
||||
*/
|
||||
template <typename MatType>
|
||||
void LogisticRegressionFunction<MatType>::FeatureGradient(
|
||||
void LogisticRegressionFunction<MatType>::PartialGradient(
|
||||
const arma::mat& parameters,
|
||||
const size_t j,
|
||||
arma::sp_mat& gradient) const
|
||||
|
||||
@@ -206,7 +206,7 @@ void SoftmaxRegressionFunction::Gradient(const arma::mat& parameters,
|
||||
}
|
||||
}
|
||||
|
||||
void SoftmaxRegressionFunction::FeatureGradient(const arma::mat& parameters,
|
||||
void SoftmaxRegressionFunction::PartialGradient(const arma::mat& parameters,
|
||||
const size_t j,
|
||||
arma::sp_mat& gradient) const
|
||||
{
|
||||
|
||||
@@ -120,7 +120,7 @@ class SoftmaxRegressionFunction
|
||||
* gradient is to be computed.
|
||||
* @param gradient Out param for the gradient value.
|
||||
*/
|
||||
void FeatureGradient(const arma::mat& parameters,
|
||||
void PartialGradient(const arma::mat& parameters,
|
||||
size_t j,
|
||||
arma::sp_mat& gradient) const;
|
||||
|
||||
|
||||
@@ -96,9 +96,9 @@ BOOST_AUTO_TEST_CASE(GreedyDescentTest)
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that LogisticRegressionFunction::FeatureGradient() works as expected.
|
||||
* Test that LogisticRegressionFunction::PartialGradient() works as expected.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(LogisticRegressionFunctionFeatureGradientTest)
|
||||
BOOST_AUTO_TEST_CASE(LogisticRegressionFunctionPartialGradientTest)
|
||||
{
|
||||
// Evaluate the gradient and feature gradient and equate.
|
||||
arma::mat predictors("0 0 0.4; 0 0 0.6; 0 0.3 0; 0.2 0 0; 0.2 -0.5 0;");
|
||||
@@ -115,16 +115,16 @@ BOOST_AUTO_TEST_CASE(LogisticRegressionFunctionFeatureGradientTest)
|
||||
for (size_t i = 0; i < f.NumFeatures(); ++i)
|
||||
{
|
||||
arma::sp_mat fGrad;
|
||||
f.FeatureGradient(testPoint, i, fGrad);
|
||||
f.PartialGradient(testPoint, i, fGrad);
|
||||
|
||||
CheckMatrices(testGradient.col(i), arma::mat(fGrad.col(i)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that SoftmaxRegressionFunction::FeatureGradient() works as expected.
|
||||
* Test that SoftmaxRegressionFunction::PartialGradient() works as expected.
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionFeatureGradientTest)
|
||||
BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionPartialGradientTest)
|
||||
{
|
||||
const size_t points = 1000;
|
||||
const size_t inputSize = 10;
|
||||
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(SoftmaxRegressionFunctionFeatureGradientTest)
|
||||
// Get the gradient for this feature.
|
||||
arma::sp_mat fGrad;
|
||||
|
||||
srf.FeatureGradient(parameters, j, fGrad);
|
||||
srf.PartialGradient(parameters, j, fGrad);
|
||||
|
||||
CheckMatrices(gradient.col(j), arma::mat(fGrad.col(j)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user