-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
random_descent.hpp
62 lines (58 loc) · 2.17 KB
/
random_descent.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @file random_descent.hpp
* @author Shikhar Bhardwaj
*
* Random descent policy for Stochastic Coordinate Descent (SCD).
*
* ensmallen is free software; you may redistribute it and/or modify it under
* the terms of the 3-clause BSD license. You should have received a copy of
* the 3-clause BSD license along with ensmallen. If not, see
* http://www.opensource.org/licenses/BSD-3-Clause for more information.
*/
#ifndef ENSMALLEN_SCD_DESCENT_POLICIES_RANDOM_HPP
#define ENSMALLEN_SCD_DESCENT_POLICIES_RANDOM_HPP
namespace ens {
/**
* Random descent policy for Stochastic Coordinate Descent(SCD). This
* descent scheme picks a the co-ordinate for the descent uniformly randomly.
*
* For more information, see the following.
* @code
* @inproceedings{ShalevShwartz2009,
* author = {Shalev-Shwartz, Shai and Tewari, Ambuj},
* title = {Stochastic Methods for L1 Regularized Loss Minimization},
* booktitle = {Proceedings of the 26th Annual International Conference on
* Machine Learning},
* series = {ICML '09},
* year = {2009},
* isbn = {978-1-60558-516-1}
* }
* @endcode
*/
class RandomDescent
{
public:
/**
* The DescentFeature method is used to get the descent coordinate for the
* current iteration of the SCD optimizer. For more information regarding the
* interface of this policy with the optimizer, have a look at the SCD
* implementation.
*
* @tparam ResolvableFunctionType The type of the function to be optimized.
* @param iteration The iteration number for which the feature is to be
* obtained.
* @param iterate The current value of the decision variable.
* @param function The function to be optimized.
* @return The index of the coordinate to be descended.
*/
template<typename ResolvableFunctionType, typename MatType, typename GradType>
static size_t DescentFeature(const size_t /* iteration */,
const MatType& /* iterate */,
const ResolvableFunctionType& function)
{
return arma::as_scalar(arma::randi<arma::uvec>(
1, arma::distr_param(0, function.NumFeatures() - 1)));
}
};
} // namespace ens
#endif