Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions include/ensmallen_bits/cd/cd_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,12 @@ CD<DescentPolicyType>::Optimize(
// Controls early termination of the optimization process.
bool terminate = false;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

// Start iterating.
Callback::BeginOptimization(*this, function, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// Get the coordinate to descend on.
size_t featureIdx = descentPolicy.template DescentFeature<
Expand Down Expand Up @@ -120,9 +123,12 @@ CD<DescentPolicyType>::Optimize(
}
}

Info << "CD: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;

if (!terminate)
{
Info << "CD: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;
}

// Calculate and return final objective. No need to pay attention to the
// result of the callback.
const ElemType objective = function.Evaluate(iterate);
Expand Down
9 changes: 6 additions & 3 deletions include/ensmallen_bits/cmaes/active_cmaes_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ typename MatType::elem_type ActiveCMAES<SelectionPolicyType,
// The current visitation order (sorted by population objectives).
UVecType idx = linspace<UVecType>(0, lambda - 1, lambda);

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

// Now iterate!
Callback::BeginOptimization(*this, function, transformedIterate,
callbacks...);
Expand All @@ -163,11 +166,11 @@ typename MatType::elem_type ActiveCMAES<SelectionPolicyType,
size_t patience = 10 + (30 * iterate.n_elem / lambda) + 1;
size_t steps = 0;

for (size_t i = 1; (i != maxIterations) && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// To keep track of where we are.
idx0 = (i - 1) % 2;
idx1 = i % 2;
idx0 = i % 2;
idx1 = (i+1) % 2;

// Perform Cholesky decomposition. If the matrix is not positive definite,
// add a small value and try again.
Expand Down
9 changes: 6 additions & 3 deletions include/ensmallen_bits/cmaes/cmaes_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ typename MatType::elem_type CMAES<SelectionPolicyType,
// The current visitation order (sorted by population objectives).
UVecType idx = linspace<UVecType>(0, lambda - 1, lambda);

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

// Now iterate!
Callback::BeginOptimization(*this, function, transformedIterate,
callbacks...);
Expand All @@ -165,11 +168,11 @@ typename MatType::elem_type CMAES<SelectionPolicyType,
size_t patience = 10 + (30 * iterate.n_elem / lambda) + 1;
size_t steps = 0;

for (size_t i = 1; (i != maxIterations) && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// To keep track of where we are.
const size_t idx0 = (i - 1) % 2;
const size_t idx1 = i % 2;
const size_t idx0 = i % 2;
const size_t idx1 = (i+1) % 2;

// Perform Cholesky decomposition. If the matrix is not positive definite,
// add a small value and try again.
Expand Down
5 changes: 4 additions & 1 deletion include/ensmallen_bits/fasta/fasta_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,11 @@ FASTA<BackwardStepType>::Optimize(FunctionType& function,
ElemType currentStepSize = (ElemType) maxStepSize;
ElemType lastStepSize = (ElemType) maxStepSize;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, f, x, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// During this optimization, we want to optimize h(x) = f(x) + g(x).
// f(x) is `f`, but g(x) is specified by `BackwardStepType`.
Expand Down
5 changes: 4 additions & 1 deletion include/ensmallen_bits/fbs/fbs_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ FBS<BackwardStepType>::Optimize(FunctionType& function,
// Controls early termination of the optimization process.
bool terminate = false;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, f, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// During this optimization, we want to optimize h(x) = f(x) + g(x).
// f(x) is `f`, but g(x) is specified by `BackwardStepType`.
Expand Down
5 changes: 4 additions & 1 deletion include/ensmallen_bits/fista/fista_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,11 @@ FISTA<BackwardStepType>::Optimize(FunctionType& function,
ElemType currentStepSize = (ElemType) maxStepSize;
ElemType lastStepSize = (ElemType) maxStepSize;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, f, x, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// During this optimization, we want to optimize h(x) = f(x) + g(x).
// f(x) is `f`, but g(x) is specified by `BackwardStepType`.
Expand Down
5 changes: 4 additions & 1 deletion include/ensmallen_bits/fw/frank_wolfe_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ FrankWolfe<LinearConstrSolverType, UpdateRuleType>::Optimize(
// Controls early termination of the optimization process.
bool terminate = false;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, f, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
currentObjective = f.EvaluateWithGradient(iterate, gradient);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ GradientDescent::Optimize(FunctionType& function,
// Controls early termination of the optimization process.
bool terminate = false;

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

// Now iterate!
Callback::BeginOptimization(*this, f, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
overallObjective = f.EvaluateWithGradient(iterate, gradient);

Expand Down
12 changes: 9 additions & 3 deletions include/ensmallen_bits/iqn/iqn_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,11 @@ IQN::Optimize(SeparableFunctionType& functionIn,
BaseGradType gradient(iterate.n_rows, iterate.n_cols);
BaseMatType u = t[0];

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, function, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
for (size_t j = 0, f = 0; f < numFunctions; j++)
{
Expand Down Expand Up @@ -206,8 +209,11 @@ IQN::Optimize(SeparableFunctionType& functionIn,
}
}

Info << "IQN: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;
if (!terminate)
{
Info << "IQN: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;
}

Callback::EndOptimization(*this, function, iterate, callbacks...);
return overallObjective;
Expand Down
5 changes: 4 additions & 1 deletion include/ensmallen_bits/parallel_sgd/parallel_sgd_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ typename MatType::elem_type>::type ParallelSGD<DecayPolicyType>::Optimize(
arma::Col<size_t> visitationOrder = arma::linspace<arma::Col<size_t>>(0,
(function.NumFunctions() - 1), function.NumFunctions());

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

// Iterate till the objective is within tolerance or the maximum number of
// allowed iterations is reached. If maxIterations is 0, this will iterate
// till convergence.
Callback::BeginOptimization(*this, function, iterate, callbacks...);
for (size_t i = 1; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
// Calculate the overall objective.
lastObjective = overallObjective;
Expand Down
12 changes: 9 additions & 3 deletions include/ensmallen_bits/sa/sa_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ typename MatType::elem_type SA<CoolingScheduleType>::Optimize(
BaseMatType moveSize(rows, cols, GetFillType<BaseMatType>::none);
moveSize.fill(ElemType(initMoveCoef));

const size_t actualMaxIterations = (maxIterations == 0) ?
std::numeric_limits<size_t>::max() : maxIterations;

Callback::BeginOptimization(*this, function, iterate, callbacks...);

// Initial moves to get rid of dependency of initial states.
Expand All @@ -92,7 +95,7 @@ typename MatType::elem_type SA<CoolingScheduleType>::Optimize(
}

// Iterating and cooling.
for (size_t i = 0; i != maxIterations && !terminate; ++i)
for (size_t i = 0; i < actualMaxIterations && !terminate; ++i)
{
oldEnergy = energy;
terminate |= GenerateMove(function, iterate, accept, moveSize, energy, idx,
Expand Down Expand Up @@ -121,8 +124,11 @@ typename MatType::elem_type SA<CoolingScheduleType>::Optimize(
}
}

Warn << "SA: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;
if (!terminate)
{
Warn << "SA: maximum iterations (" << maxIterations << ") reached; "
<< "terminating optimization." << std::endl;
}

Callback::EndOptimization(*this, function, iterate, callbacks...);
return energy;
Expand Down