Skip to content

Commit b6ad106

Browse files
Apply suggestions from code review
Co-authored-by: Ryan Curtin <ryan@ratml.org>
1 parent 1f288b0 commit b6ad106

5 files changed

Lines changed: 22 additions & 22 deletions

File tree

doc/optimizers.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2470,11 +2470,11 @@ for all Lagrange multipliers and 10 is used as the initial penalty parameter.
24702470
24712471
*An optimizer for [differentiable functions](#differentiable-functions).*
24722472
2473-
A DeltaBarDelta variant that incorporates the following modifications:
2474-
- In the original DeltaBarDelta, the momentum term (delta_bar) is used
2473+
A [DeltaBarDelta](#deltabardelta) variant that incorporates the following modifications:
2474+
- In the original DeltaBarDelta, the momentum term (`delta_bar`) is used
24752475
solely for sign comparison with the current gradient and does not
24762476
participate in the parameter update. In this modified variant, the
2477-
momentum term (velocity) is directly used to update the parameters.
2477+
momentum term (`velocity`) is directly used to update the parameters.
24782478
- Instead of adjusting the step size directly, each parameter maintains
24792479
a gain value initialized to 1.0. Updates apply additive increases or
24802480
multiplicative decreases to this gain. The effective step size for a
@@ -2503,7 +2503,7 @@ Note: This variant originates from optimization of the t-SNE cost function.
25032503
| `bool` | **`resetPolicy`** | If true, parameters are reset before every `Optimize()` call. | `true` |
25042504
25052505
Attributes of the optimizer may also be modified via the member methods
2506-
`StepSize()`, `MaxIterations()`, `Tolerance()`, `Kappa()`, `Phi()`, `Momentum()`, `MinGain`, and `ResetPolicy()`.
2506+
`StepSize()`, `MaxIterations()`, `Tolerance()`, `Kappa()`, `Phi()`, `Momentum()`, `MinGain()`, and `ResetPolicy()`.
25072507
25082508
#### Examples:
25092509

include/ensmallen_bits/delta_bar_delta/update_policies/delta_bar_delta_update.hpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class DeltaBarDeltaUpdate
134134
{
135135
deltaBar.zeros(rows, cols);
136136
epsilon.set_size(rows, cols);
137-
epsilon.fill(parent.InitialStepSize());
137+
epsilon.fill(ElemType(parent.InitialStepSize()));
138138
}
139139

140140
/**
@@ -145,15 +145,14 @@ class DeltaBarDeltaUpdate
145145
* @param delta The gradient matrix.
146146
*/
147147
void Update(MatType& iterate,
148-
const double stepSize,
148+
const double /* stepSize */,
149149
const GradType& delta)
150150
{
151151
const MatType signMatrix = sign(delta % deltaBar);
152152

153-
epsilon += (signMatrix == +1) * kappa -
154-
(signMatrix == -1) * phi % epsilon;
155-
epsilon.clamp(minStepSize,
156-
arma::Datum<typename MatType::elem_type>::inf);
153+
epsilon += conv_to<MatType>((signMatrix == +1) * kappa -
154+
(signMatrix == -1) * phi % epsilon);
155+
epsilon.clamp(minStepSize, arma::Datum<ElemType>::inf);
157156

158157
deltaBar = theta * deltaBar + (1 - theta) * delta;
159158
iterate -= epsilon % delta;

include/ensmallen_bits/delta_bar_delta/update_policies/momentum_delta_bar_delta_update.hpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ class MomentumDeltaBarDeltaUpdate
133133
const double stepSize,
134134
const GradType& gradient)
135135
{
136-
gains += (sign(gradient) != sign(velocity)) * kappa -
137-
(sign(gradient) == sign(velocity)) * (1 - phi) % gains;
138-
gains.clamp(minGain, arma::Datum<typename MatType::elem_type>::inf);
136+
gains += conv_to<MatType>::from(
137+
(sign(gradient) != sign(velocity)) * kappa -
138+
(sign(gradient) == sign(velocity)) * (1 - phi) % gains);
139+
gains.clamp(minGain, arma::Datum<ElemType>::inf);
139140

140-
velocity = momentum * velocity - (stepSize * gains) % gradient;
141+
velocity = momentum * velocity - (ElemType(stepSize) * gains) % gradient;
141142
iterate += velocity;
142143
}
143144

tests/delta_bar_delta_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ TEMPLATE_TEST_CASE("DeltaBarDelta_GDTestFunction", "[DeltaBarDelta]",
2929
}
3030

3131
TEMPLATE_TEST_CASE("DeltaBarDelta_RosenbrockFunction", "[DeltaBarDelta]",
32-
ENS_ALL_TEST_TYPES)
32+
ENS_ALL_CPU_TEST_TYPES)
3333
{
34-
DeltaBarDelta s(0.001, 0, Tolerances<TestType>::Obj / 100,
34+
DeltaBarDelta s(0.001, 100000, Tolerances<TestType>::Obj / 100,
3535
0.0001, 0.2, 0.5);
3636
FunctionTest<RosenbrockFunction, TestType>(s,
3737
10 * Tolerances<TestType>::LargeObj,
@@ -41,7 +41,7 @@ TEMPLATE_TEST_CASE("DeltaBarDelta_RosenbrockFunction", "[DeltaBarDelta]",
4141
TEMPLATE_TEST_CASE("DeltaBarDelta_LogisticRegressionFunction",
4242
"[DeltaBarDelta]", ENS_ALL_TEST_TYPES)
4343
{
44-
DeltaBarDelta s(0.0008, 20, Tolerances<TestType>::Obj,
44+
DeltaBarDelta s(0.0001, 500, Tolerances<TestType>::Obj,
4545
0.00008, 0.2, 0.5);
4646
LogisticRegressionFunctionTest<TestType>(s);
4747
}

tests/momentum_delta_bar_delta_test.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ using namespace ens::test;
2222
TEMPLATE_TEST_CASE("MomentumDeltaBarDelta_GDTestFunction",
2323
"[MomentumDeltaBarDelta]", ENS_ALL_TEST_TYPES)
2424
{
25-
MomentumDeltaBarDelta s(0.9, 50, 1e-9, 0.2, 0.8, 0.5);
25+
MomentumDeltaBarDelta s(0.1, 1000, 1e-9, 0.2, 0.8, 0.5);
2626
FunctionTest<GDTestFunction, TestType>(s,
2727
Tolerances<TestType>::LargeObj,
2828
Tolerances<TestType>::LargeCoord);
2929
}
3030

3131
TEMPLATE_TEST_CASE("MomentumDeltaBarDelta_RosenbrockFunction",
32-
"[MomentumDeltaBarDelta]", ENS_ALL_TEST_TYPES)
32+
"[MomentumDeltaBarDelta]", ENS_ALL_CPU_TEST_TYPES)
3333
{
34-
MomentumDeltaBarDelta s(0.001, 0, Tolerances<TestType>::Obj / 100,
35-
0.2, 0.8, 0.5);
34+
MomentumDeltaBarDelta s(0.001, 100000, Tolerances<TestType>::Obj / 100, 0.2,
35+
0.8, 0.5);
3636
FunctionTest<RosenbrockFunction, TestType>(s,
3737
10 * Tolerances<TestType>::LargeObj,
3838
10 * Tolerances<TestType>::LargeCoord);
@@ -41,7 +41,7 @@ TEMPLATE_TEST_CASE("MomentumDeltaBarDelta_RosenbrockFunction",
4141
TEMPLATE_TEST_CASE("MomentumDeltaBarDelta_LogisticRegressionFunction",
4242
"[MomentumDeltaBarDelta]", ENS_ALL_TEST_TYPES)
4343
{
44-
MomentumDeltaBarDelta s(0.0004, 20, Tolerances<TestType>::Obj,
44+
MomentumDeltaBarDelta s(0.00005, 2000, Tolerances<TestType>::Obj,
4545
0.2, 0.8, 0.5);
4646
LogisticRegressionFunctionTest<TestType>(s);
4747
}

0 commit comments

Comments
 (0)