csolnp_ms | R Documentation |
Runs the csolnp solver from multiple diverse feasible starting values and returns the best solution found.
csolnp_ms(
fn,
gr = NULL,
eq_fn = NULL,
eq_b = NULL,
eq_jac = NULL,
ineq_fn = NULL,
ineq_lower = NULL,
ineq_upper = NULL,
ineq_jac = NULL,
lower = NULL,
upper = NULL,
control = list(),
n_candidates = 20,
penalty = 10000,
eq_tol = 1e-06,
ineq_tol = 1e-06,
seed = NULL,
return_all = FALSE,
...
)
fn |
the objective function (must return a scalar). |
gr |
an optional function for computing the analytic gradient of the function (must return a vector of length n). |
eq_fn |
an optional function for calculating equality constraints. |
eq_b |
a vector of the equality bounds (if eq_fn provided). |
eq_jac |
an optional function for computing the analytic Jacobian of the equality function (a matrix with number of columns n and number of rows equal to the number of equalities). |
ineq_fn |
an optional function for calculating inequality constraints. |
ineq_lower |
the lower bounds for the inequality constraints (must be finite). |
ineq_upper |
the upper bounds for the inequality constraints (must be finite). |
ineq_jac |
an optional function for computing the analytic Jacobian of the inequality function (a matrix with number of columns n and number of rows equal to the number of inequalities). |
lower |
lower bounds for the parameters. This is strictly required. |
upper |
upper bounds for the parameters. This is strictly required. |
control |
a list of solver control parameters (see details). |
n_candidates |
integer. The number of initial feasible candidate points to generate for multi-start optimization. Default is 20. |
penalty |
numeric. The penalty parameter used when projecting to feasibility for candidate generation. Default is 1e4. |
eq_tol |
Numeric. Tolerance for equality constraint violation
(default is 1e-6). Candidate solutions with |
ineq_tol |
Numeric. Tolerance for inequality constraint violation
(default is 1e-6). Candidate solutions with |
seed |
an optional random seed used to initialize the random number generator for the random samples. |
return_all |
logical. Whether to return all solutions as a list. This may be useful for debugging. |
... |
additional arguments passed to the supplied functions (common to all functions supplied). |
This function automates the process of generating multiple feasible starting
points (using lower, upper, and constraint information), runs csolnp
from
each, and returns the solution with the lowest objective value. It is useful
for problems where local minima are a concern or the objective surface is
challenging.
Candidate Generation:
The generate_feasible_starts
approach creates a diverse set of initial
parameter vectors (candidates) that are feasible with respect to box and
(optionally) nonlinear constraints. The process is as follows:
For each candidate, a random point is sampled inside the parameter
box constraints (lower
and upper
) but a small distance away
from the boundaries, to avoid numerical issues. This is achieved by a helper
function that applies a user-specified buffer (eps
).
If nonlinear inequality constraints (ineq_fn
) are provided,
each sampled point is projected towards the feasible region using a
fast penalized minimization. This step does not solve the feasibility problem
exactly, but quickly produces a point that satisfies the constraints to
within a specified tolerance, making it suitable as a starting point for
optimization.
If only box constraints are present, the sampled point is used directly as a feasible candidate.
The set of feasible candidates is ranked by the objective with lower values considered better. This allows prioritization of candidates that start closer to optimality.
This method efficiently creates a diverse set of robust initial values, improving
the chances that multi-start optimization will identify the global or a
high-quality local solution, especially in the presence of non-convexities or
challenging constraint boundaries.
Solution Selection:
For each candidate starting point, csolnp_ms
runs the csolnp
solver
and collects the resulting solutions and their associated KKT diagnostics. If
equality or inequality constraints are present, candidate solutions are first
filtered to retain only those for which the maximum violation of
equality (kkt_diagnostics\$eq_violation
) and/or
inequality (kkt_diagnostics\$ineq_violation
) constraints are less than
or equal to user-specified tolerances (eq_tol
and ineq_tol
).
Among the feasible solutions (those satisfying all constraints within tolerance),
the solution with the lowest objective value is selected and returned as the
best result. If no candidate fully satisfies the constraints, the solution with
the smallest total constraint violation is returned, with a warning issued to
indicate that strict feasibility was not achieved. This two-stage selection
process ensures that the final result is both feasible (when possible) and
optimally minimizes the objective function among all feasible candidates.
A list containing the best solution found by multi-start, with elements analogous
to those returned by csolnp
. If return_all
is TRUE, then a list of
all solutions is returned instead.
Alexios Galanos
csolnp
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.