Skip to content

Commit ea649d1

Browse files
author
Teseo Schneider
committed
multi solver updates
1 parent fdf0f64 commit ea649d1

File tree

10 files changed

+272
-131
lines changed

10 files changed

+272
-131
lines changed

non-linear-solver-spec.json

Lines changed: 115 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"iterations_per_strategy",
1313
"line_search",
1414
"allow_out_of_iterations",
15-
"LBFGS",
16-
"LBFGSB",
15+
"L-BFGS",
16+
"L-BFGS-B",
1717
"Newton",
1818
"StochasticGradientDescent",
1919
"box_constraints",
@@ -23,17 +23,10 @@
2323
},
2424
{
2525
"pointer": "/solver",
26-
"doc": "Nonlinear solver type. If a list, list of solvers for ballback. Eg, ['Newton', 'L-BFGS', 'GradientDescent'] will solve using Newton, in case of failure will fallback to L-BFGS and eventually to GradientDescent",
27-
"type": "list"
28-
},
29-
{
30-
"pointer": "/solver/*",
3126
"default": "Newton",
3227
"type": "string",
3328
"options": [
3429
"Newton",
35-
"ProjectedNewton",
36-
"RegularizedNewton",
3730
"DenseNewton",
3831
"GradientDescent",
3932
"StochasticGradientDescent",
@@ -94,7 +87,7 @@
9487
"doc": "If false (default), an exception will be thrown when the nonlinear solver reaches the maximum number of iterations."
9588
},
9689
{
97-
"pointer": "/LBFGS",
90+
"pointer": "/L-BFGS",
9891
"default": null,
9992
"type": "object",
10093
"optional": [
@@ -103,22 +96,22 @@
10396
"doc": "Options for LBFGS."
10497
},
10598
{
106-
"pointer": "/LBFGS/history_size",
99+
"pointer": "/L-BFGS/history_size",
107100
"default": 6,
108101
"type": "int",
109102
"doc": "The number of corrections to approximate the inverse Hessian matrix."
110103
},
111104
{
112-
"pointer": "/LBFGSB",
105+
"pointer": "/L-BFGS-B",
113106
"default": null,
114107
"type": "object",
115108
"optional": [
116109
"history_size"
117110
],
118-
"doc": "Options for the boxed LBFGS."
111+
"doc": "Options for the boxed L-BFGS."
119112
},
120113
{
121-
"pointer": "/LBFGSB/history_size",
114+
"pointer": "/L-BFGS-B/history_size",
122115
"default": 6,
123116
"type": "int",
124117
"doc": "The number of corrections to approximate the inverse Hessian matrix."
@@ -174,70 +167,154 @@
174167
"doc": "Use PSD as fallback using second order solvers (i.e., Newton's method)."
175168
},
176169
{
177-
"pointer": "/ProjectedNewton",
170+
"pointer": "/StochasticGradientDescent",
178171
"default": null,
179172
"type": "object",
180173
"optional": [
181-
"residual_tolerance"
174+
"erase_component_probability"
182175
],
183-
"doc": "Options for projected Newton."
176+
"doc": "Options for Stochastic Gradient Descent."
184177
},
185178
{
186-
"pointer": "/ProjectedNewton/residual_tolerance",
187-
"default": 1e-5,
179+
"pointer": "/StochasticGradientDescent/erase_component_probability",
180+
"default": 0.3,
188181
"type": "float",
189-
"doc": "Tolerance of the linear system residual. If residual is above, the direction is rejected."
182+
"doc": "Probability of erasing a component on the gradient for StochasticGradientDescent."
190183
},
191184
{
192-
"pointer": "/RegularizedNewton",
193-
"default": null,
185+
"pointer": "/solver",
186+
"type": "list",
187+
"doc": "List of solvers for ballback. Eg, [{'type':'Newton'}, {'type':'L-BFGS'}, {'type':'GradientDescent'}] will solve using Newton, in case of failure will fallback to L-BFGS and eventually to GradientDescent"
188+
},
189+
{
190+
"pointer": "/solver/*",
191+
"type": "object",
192+
"type_name": "Newton",
193+
"optional": [
194+
"residual_tolerance"
195+
],
196+
"doc": "Options for Newton."
197+
},
198+
{
199+
"pointer": "/solver/*",
200+
"type": "object",
201+
"type_name": "ProjectedNewton",
202+
"optional": [
203+
"residual_tolerance"
204+
],
205+
"doc": "Options for Newton."
206+
},
207+
{
208+
"pointer": "/solver/*",
209+
"type": "object",
210+
"type_name": "RegularizedNewton",
211+
"optional": [
212+
"residual_tolerance",
213+
"reg_weight_min",
214+
"reg_weight_max",
215+
"reg_weight_inc"
216+
],
217+
"doc": "Options for Newton."
218+
},
219+
{
220+
"pointer": "/solver/*",
221+
"type": "object",
222+
"type_name": "DenseNewton",
223+
"optional": [
224+
"residual_tolerance"
225+
],
226+
"doc": "Options for Newton."
227+
},
228+
{
229+
"pointer": "/solver/*",
230+
"type": "object",
231+
"type_name": "DenseProjectedNewton",
232+
"optional": [
233+
"residual_tolerance"
234+
],
235+
"doc": "Options for Newton."
236+
},
237+
{
238+
"pointer": "/solver/*",
194239
"type": "object",
240+
"type_name": "DenseRegularizedNewton",
195241
"optional": [
196242
"residual_tolerance",
197243
"reg_weight_min",
198244
"reg_weight_max",
199245
"reg_weight_inc"
200246
],
201-
"doc": "Options for regularized Newton."
247+
"doc": "Options for Newton."
202248
},
203249
{
204-
"pointer": "/RegularizedNewton/residual_tolerance",
250+
"pointer": "/solver/*",
251+
"type": "object",
252+
"type_name": "GradientDescent",
253+
"doc": "Options for Gradient Descent."
254+
},
255+
{
256+
"pointer": "/solver/*",
257+
"type": "object",
258+
"type_name": "StochasticGradientDescent",
259+
"optional": [
260+
"erase_component_probability"
261+
],
262+
"doc": "Options for Stochastic Gradient Descent."
263+
},
264+
{
265+
"pointer": "/solver/*",
266+
"type": "object",
267+
"type_name": "L-BFGS",
268+
"optional": [
269+
"erase_component_probability",
270+
"history_size"
271+
],
272+
"doc": "Options for L-BFGS."
273+
},
274+
{
275+
"pointer": "/solver/*",
276+
"type": "object",
277+
"type_name": "BFGS",
278+
"optional": [
279+
"erase_component_probability"
280+
],
281+
"doc": "Options for BFGS."
282+
},
283+
{
284+
"pointer": "/solver/*/residual_tolerance",
205285
"default": 1e-5,
206286
"type": "float",
207287
"doc": "Tolerance of the linear system residual. If residual is above, the direction is rejected."
208288
},
209289
{
210-
"pointer": "/RegularizedNewton/reg_weight_min",
290+
"pointer": "/solver/*/reg_weight_min",
211291
"default": 1e-8,
212292
"type": "float",
213293
"doc": "Minimum regulariztion weight."
214294
},
215295
{
216-
"pointer": "/RegularizedNewton/reg_weight_max",
296+
"pointer": "/solver/*/reg_weight_max",
217297
"default": 1e8,
218298
"type": "float",
219299
"doc": "Maximum regulariztion weight."
220300
},
221301
{
222-
"pointer": "/RegularizedNewton/reg_weight_inc",
302+
"pointer": "/solver/*/reg_weight_inc",
223303
"default": 10,
224304
"type": "float",
225305
"doc": "Regulariztion weight increment."
226306
},
227307
{
228-
"pointer": "/StochasticGradientDescent",
229-
"default": null,
230-
"type": "object",
231-
"optional": [
232-
"erase_component_probability"
233-
],
234-
"doc": "Options for Stochastic Gradient Descent."
235-
},
236-
{
237-
"pointer": "/StochasticGradientDescent/erase_component_probability",
308+
"pointer": "/solver/*/erase_component_probability",
238309
"default": 0.3,
239310
"type": "float",
240-
"doc": "Probability of erasing a component on the gradient for StochasticGradientDescent."
311+
"doc": "Probability of erasing a component on the gradient for stochastic solvers."
312+
},
313+
{
314+
"pointer": "/solver/*/history_size",
315+
"default": 6,
316+
"type": "int",
317+
"doc": "The number of corrections to approximate the inverse Hessian matrix."
241318
},
242319
{
243320
"pointer": "/line_search",

src/polysolve/nonlinear/BoxConstraintSolver.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace polysolve::nonlinear
4242

4343
const std::string solver_name = solver_params["solver"];
4444

45-
auto solver = std::make_unique<BoxConstraintSolver>(solver_name, solver_params, characteristic_length, logger);
45+
auto solver = std::make_unique<BoxConstraintSolver>(solver_params, characteristic_length, logger);
4646

4747
if (solver_name == "LBFGSB" || solver_name == "L-BFGS-B")
4848
{
@@ -70,11 +70,10 @@ namespace polysolve::nonlinear
7070
"MMA"};
7171
}
7272

73-
BoxConstraintSolver::BoxConstraintSolver(const std::string &name,
74-
const json &solver_params,
73+
BoxConstraintSolver::BoxConstraintSolver(const json &solver_params,
7574
const double characteristic_length,
7675
spdlog::logger &logger)
77-
: Superclass(name, solver_params, characteristic_length, logger)
76+
: Superclass(solver_params, characteristic_length, logger)
7877
{
7978
json box_constraint_params = solver_params["box_constraints"];
8079
max_change_ = box_constraint_params["max_change"];
@@ -162,8 +161,8 @@ namespace polysolve::nonlinear
162161
}
163162

164163
void BoxConstraintSolver::add_constraint(const std::shared_ptr<Problem> &constraint)
165-
{
166-
for (auto& strategy : m_strategies)
164+
{
165+
for (auto &strategy : m_strategies)
167166
if (strategy->name() == "MMA")
168167
std::dynamic_pointer_cast<MMA>(strategy)->add_constraint(constraint);
169168
}

src/polysolve/nonlinear/BoxConstraintSolver.hpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ namespace polysolve::nonlinear
2727

2828
using Superclass = Solver;
2929

30-
BoxConstraintSolver(const std::string &name,
31-
const json &solver_params,
30+
BoxConstraintSolver(const json &solver_params,
3231
const double characteristic_length,
3332
spdlog::logger &logger);
3433

0 commit comments

Comments
 (0)