Skip to content

Commit a29ecf1

Browse files
Merge pull request #431 from SciML/optdocs
Update `OptimizationFunction`, `OptimizationProblem` and `solve` docstrings
2 parents 37042e1 + 7b733bd commit a29ecf1

File tree

3 files changed

+143
-122
lines changed

3 files changed

+143
-122
lines changed

src/problems/basic_problems.jl

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -547,16 +547,16 @@ Documentation Page: https://docs.sciml.ai/Optimization/stable/API/optimization_p
547547
548548
## Mathematical Specification of an Optimization Problem
549549
550-
To define an Optimization Problem, you simply need to give the function ``f``
551-
which defines the cost function to minimize:
550+
To define an optimization problem, you need the objective function ``f``
551+
which is minimized over the domain of ``u``, the collection of optimization variables:
552552
553553
```math
554554
min_u f(u,p)
555555
```
556556
557-
``u₀`` is an initial guess of the minimum. `f` should be specified as `f(u,p)`
558-
and `u₀` should be an AbstractArray (or number) whose geometry matches the
559-
desired geometry of `u`. Note that we are not limited to numbers or vectors
557+
``u₀`` is an initial guess for the minimizer. `f` should be specified as `f(u,p)`
558+
and `u₀` should be an `AbstractArray` whose geometry matches the
559+
desired geometry of `u`. Note that we are not limited to vectors
560560
for `u₀`; one is allowed to provide `u₀` as arbitrary matrices /
561561
higher-dimension tensors as well.
562562
@@ -574,27 +574,27 @@ OptimizationProblem{iip}(f, u0, p = SciMLBase.NullParameters(),;
574574
kwargs...)
575575
```
576576
577-
`isinplace` optionally sets whether the function is in-place or not. This is
578-
determined automatically, but not inferred. Note that for OptimizationProblem,
579-
in-place only refers to the Jacobian and Hessian functions, and thus by default
580-
if the `OptimizationFunction` is not defined directly then `iip = true` is
581-
done by default.
577+
`isinplace` optionally sets whether the function is in-place or not.
578+
This is determined automatically, but not inferred. Note that for OptimizationProblem,
579+
in-place refers to the objective's derivative functions, the constraint function
580+
and its derivatives. `OptimizationProblem` currently only supports in-place.
582581
583-
Parameters are optional, and if not given, then a `NullParameters()` singleton
582+
Parameters `p` are optional, and if not given, then a `NullParameters()` singleton
584583
will be used, which will throw nice errors if you try to index non-existent
585-
parameters. Any extra keyword arguments are passed on to the solvers. For example,
586-
if you set a `callback` in the problem, then that `callback` will be added in
587-
every solve call.
584+
parameters.
588585
589586
`lb` and `ub` are the upper and lower bounds for box constraints on the
590-
optimization. They should be an `AbstractArray` matching the geometry of `u`,
591-
where `(lb[I],ub[I])` is the box constraint (lower and upper bounds)
592-
for `u[I]`.
587+
optimization variables. They should be an `AbstractArray` matching the geometry of `u`,
588+
where `(lb[i],ub[i])` is the box constraint (lower and upper bounds) for `u[i]`.
589+
590+
`lcons` and `ucons` are the upper and lower bounds in case of inequality constraints on the
591+
optimization and if they are set to be equal then it represents an equality constraint.
592+
They should be an `AbstractArray` matching the geometry of `u`, where `(lcons[i],ucons[i])`
593+
are the lower and upper bounds for `cons[i]`.
593594
594-
`lcons` and `ucons` are the upper and lower bounds for equality constraints on the
595-
optimization. They should be an `AbstractArray` matching the geometry of `u`,
596-
where `(lcons[I],ucons[I])` is the constraint (lower and upper bounds)
597-
for `cons[I]`.
595+
The `f` in the `OptimizationProblem` should typically be an instance of [`OptimizationFunction`](@ref)
596+
to specify the objective function and its derivatives either by passing
597+
predefined functions for them or automatically generated using the [`ADType`](@ref).
598598
599599
If `f` is a standard Julia function, it is automatically transformed into an
600600
`OptimizationFunction` with `NoAD()`, meaning the derivative functions are not
@@ -605,12 +605,13 @@ Any extra keyword arguments are captured to be sent to the optimizers.
605605
### Fields
606606
607607
* `f`: the function in the problem.
608-
* `u0`: the initial guess for the optima.
609-
* `p`: the parameters for the problem. Defaults to `NullParameters`.
610-
* `lb`: the lower bounds for the optimization of `u`.
611-
* `ub`: the upper bounds for the optimization of `u`.
612-
* `int`: integrality indicator for `u`.
613-
* `lcons`: the vector of lower bounds for the constraints passed to [`OptimizationFunction`](@ref).
608+
* `u0`: the initial guess for the optimization variables.
609+
* `p`: the constant parameters used for defining the problem. Defaults to `NullParameters`.
610+
* `lb`: the lower bounds for the optimization variables `u`.
611+
* `ub`: the upper bounds for the optimization variables `u`.
612+
* `int`: integrality indicator for `u`. If `int[i] == true`, then `u[i]` is an integer variable.
613+
Defaults to `nothing`, implying no integrality constraints.
614+
* `lcons`: the vector of lower bounds for the constraints passed to [OptimizationFunction](@ref).
614615
Defaults to `nothing`, implying no lower bounds for the constraints (i.e. the constraint bound is `-Inf`)
615616
* `ucons`: the vector of upper bounds for the constraints passed to [`OptimizationFunction`](@ref).
616617
Defaults to `nothing`, implying no upper bounds for the constraints (i.e. the constraint bound is `Inf`)
@@ -619,7 +620,7 @@ Any extra keyword arguments are captured to be sent to the optimizers.
619620
620621
## Inequality and Equality Constraints
621622
622-
Both inequality and equality constraints are defined by the `f.cons` function in the `OptimizationFunction`
623+
Both inequality and equality constraints are defined by the `f.cons` function in the [`OptimizationFunction`](@ref)
623624
description of the problem structure. This `f.cons` is given as a function `f.cons(u,p)` which computes
624625
the value of the constraints at `u`. For example, take `f.cons(u,p) = u[1] - u[2]`.
625626
With these definitions, `lcons` and `ucons` define the bounds on the constraint that the solvers try to satisfy.

0 commit comments

Comments
 (0)