Fix style and bibliography.

This commit is contained in:
Ryan Curtin
2019-04-07 22:05:07 -04:00
parent 121bd722a2
commit 6eaf338ea3
4 changed files with 30 additions and 42 deletions
+3 -2
View File
@@ -6,8 +6,9 @@
* Where relevant, all models with a `Train()` method now return a `double`
value representing the goodness of fit (i.e. final objective value, error,
etc.) (#1678).
* Add implementation for linear support vector machine(see src/mlpack/methods/linear_svm).
* Add implementation for linear support vector machine (see
`src/mlpack/methods/linear_svm`).
### mlpack 3.0.5
###### ????-??-??
+4 -3
View File
@@ -35,8 +35,9 @@ namespace svm {
* @inproceedings{weston1999support,
* title = {Support vector machines for multi-class pattern
* recognition.},
* author = {Weston, Jason and Watkins, Chris and others},
* booktitle = {Esann},
* author = {Weston, Jason and Watkins, Chris},
* booktitle = {Proceedings of the 7th European Symposium on Artifical Neural
* Networks (ESANN '99)},
* volume = {99},
* pages = {219--224},
* year = {1999}
@@ -47,7 +48,7 @@ namespace svm {
* @article{cortes1995support,
* title = {Support-vector networks},
* author = {Cortes, Corinna and Vapnik, Vladimir},
* journal = {Machine learning},
* journal = {Machine Learning},
* volume = {20},
* number = {3},
* pages = {273--297},
@@ -187,8 +187,7 @@ double LinearSVMFunction<MatType>::Evaluate(
loss = arma::accu(arma::clamp(margin, 0.0, DBL_MAX)) / dataset.n_cols;
// Adding the regularization term.
regularization = 0.5 * lambda * arma::dot(parameters,
parameters);
regularization = 0.5 * lambda * arma::dot(parameters, parameters);
return loss + regularization;
}
@@ -229,8 +228,7 @@ double LinearSVMFunction<MatType>::Evaluate(
loss /= batchSize;
// Adding the regularization term.
regularization = 0.5 * lambda * arma::dot(parameters,
parameters);
regularization = 0.5 * lambda * arma::dot(parameters, parameters);
cost = loss + regularization;
return cost;
@@ -340,18 +338,15 @@ void LinearSVMFunction<MatType>::Gradient(
// Check intercept condition
if (!fitIntercept)
{
gradient = dataset.cols(firstId, lastId)
* difference.t();
gradient = dataset.cols(firstId, lastId) * difference.t();
}
else
{
gradient.set_size(size(parameters));
gradient.submat(0, 0, parameters.n_rows - 2, parameters.n_cols - 1) =
dataset.cols(firstId, lastId)
* difference.t();
dataset.cols(firstId, lastId) * difference.t();
gradient.row(parameters.n_rows - 1) =
arma::ones<arma::rowvec>(batchSize)
* difference.t();
arma::ones<arma::rowvec>(batchSize) * difference.t();
}
gradient /= batchSize;
@@ -418,8 +413,7 @@ double LinearSVMFunction<MatType>::EvaluateWithGradient(
loss /= dataset.n_cols;
// Adding the regularization term.
regularization = 0.5 * lambda * arma::dot(parameters,
parameters);
regularization = 0.5 * lambda * arma::dot(parameters, parameters);
cost = loss + regularization;
return cost;
@@ -468,18 +462,15 @@ double LinearSVMFunction<MatType>::EvaluateWithGradient(
// Check intercept condition
if (!fitIntercept)
{
gradient = dataset.cols(firstId, lastId)
* difference.t();
gradient = dataset.cols(firstId, lastId) * difference.t();
}
else
{
gradient.set_size(size(parameters));
gradient.submat(0, 0, parameters.n_rows - 2, parameters.n_cols - 1) =
dataset.cols(firstId, lastId)
* difference.t();
dataset.cols(firstId, lastId) * difference.t();
gradient.row(parameters.n_rows - 1) =
arma::ones<arma::rowvec>(batchSize)
* difference.t();
arma::ones<arma::rowvec>(batchSize) * difference.t();
}
gradient /= batchSize;
@@ -489,13 +480,11 @@ double LinearSVMFunction<MatType>::EvaluateWithGradient(
gradient += lambda * parameters;
// The Hinge Loss Function
loss = arma::accu(arma::clamp(margin.cols(firstId, lastId),
0.0, DBL_MAX));
loss = arma::accu(arma::clamp(margin.cols(firstId, lastId), 0.0, DBL_MAX));
loss /= batchSize;
// Adding the regularization term.
regularization = 0.5 * lambda * arma::dot(parameters,
parameters);
regularization = 0.5 * lambda * arma::dot(parameters, parameters);
cost = loss + regularization;
return cost;
@@ -48,8 +48,8 @@ LinearSVM<MatType>::LinearSVM(
delta(delta),
fitIntercept(fitIntercept)
{
LinearSVMFunction<MatType>::InitializeWeights(
parameters, inputSize, numClasses, fitIntercept);
LinearSVMFunction<MatType>::InitializeWeights( parameters, inputSize,
numClasses, fitIntercept);
}
template <typename MatType>
@@ -60,8 +60,8 @@ double LinearSVM<MatType>::Train(
const size_t numClasses,
OptimizerType optimizer)
{
LinearSVMFunction<MatType> svm(data, labels,
numClasses, lambda, delta, fitIntercept);
LinearSVMFunction<MatType> svm(data, labels, numClasses, lambda, delta,
fitIntercept);
if (parameters.is_empty())
parameters = svm.InitialPoint();
@@ -79,8 +79,7 @@ double LinearSVM<MatType>::Train(
template <typename MatType>
void LinearSVM<MatType>::Classify(
const MatType& data,
arma::Row<size_t>& labels)
const
arma::Row<size_t>& labels) const
{
arma::mat scores;
Classify(data, labels, scores);
@@ -90,13 +89,13 @@ template <typename MatType>
void LinearSVM<MatType>::Classify(
const MatType& data,
arma::Row<size_t>& labels,
arma::mat& scores)
const
arma::mat& scores) const
{
Classify(data, scores);
#if ARMA_VERSION_MAJOR > 7 || ARMA_VERSION_MAJOR == 7 \
&& ARMA_VERSION_MINOR >= 300
#if ARMA_VERSION_MAJOR > 7 || \
(ARMA_VERSION_MAJOR == 7 && \
ARMA_VERSION_MINOR >= 300)
// Prepare necessary data
labels.zeros(data.n_cols);
@@ -134,8 +133,7 @@ const
template <typename MatType>
void LinearSVM<MatType>::Classify(
const MatType& data,
arma::mat& scores)
const
arma::mat& scores) const
{
if (data.n_rows != FeatureSize())
{
@@ -169,8 +167,7 @@ size_t LinearSVM<MatType>::Classify(const VecType& point) const
template <typename MatType>
double LinearSVM<MatType>::ComputeAccuracy(
const MatType& testData,
const arma::Row<size_t>& testLabels)
const
const arma::Row<size_t>& testLabels) const
{
arma::Row<size_t> labels;
@@ -184,7 +181,7 @@ const
count++;
// Return the accuracy.
return (double)count / labels.n_elem;
return (double) count / labels.n_elem;
}
} // namespace svm