Skip to content

Commit d122a84

Browse files
Merge pull request #913 from SciML/ChrisRackauckas-patch-2
Extend getting_started.md
2 parents c481246 + f43c591 commit d122a84

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

docs/src/getting_started.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
In this tutorial, we introduce the basics of Optimization.jl by showing
44
how to easily mix local optimizers and global optimizers on the Rosenbrock equation.
5+
6+
The Rosenbrock equation is defined as follows:
7+
8+
```math
9+
f(u,p) = (p_1 - u_1)^2 + p_2 * ( u_2 - u_1^2)^2
10+
```
11+
12+
This is a parameterized optimization problem where we want to solve for the vector `u` s.t. `u` minimizes `f`.
513
The simplest copy-pasteable code using a quasi-Newton method (LBFGS) to solve the Rosenbrock problem is the following:
614

715
```@example intro
@@ -17,6 +25,59 @@ prob = OptimizationProblem(optf, u0, p)
1725
sol = solve(prob, Optimization.LBFGS())
1826
```
1927

28+
```@example intro
29+
sol.u
30+
```
31+
32+
```@example intro
33+
sol.objective
34+
```
35+
36+
Tada! That's how you do it. Now let's dive in a little more into what each part means and how to customize it all to your needs.
37+
38+
## Understanding the Solution Object
39+
40+
The solution object is a `SciMLBase.AbstractNoTimeSolution`, and thus it follows the
41+
[SciMLBase Solution Interface for non-timeseries objects](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/) and is documented at the [solution type page](@ref solution).
42+
However, for simplicity let's show a bit of it in action.
43+
44+
An optimization solution has an array interface so that it acts like the array that it solves for. This array syntax is shorthand for simply grabbing the solution `u`. For example:
45+
46+
```@example intro
47+
sol[1] == sol.u[1]
48+
```
49+
50+
```@example intro
51+
Array(sol) == sol.u
52+
```
53+
54+
`sol.objective` returns the final cost of the optimization. We can validate this by plugging it into our function:
55+
56+
```@example intro
57+
rosenbrock(sol.u, p)
58+
```
59+
60+
```@example intro
61+
sol.objective
62+
```
63+
64+
The `sol.retcode` gives us more information about the solution process.
65+
66+
```@example intro
67+
sol.retcode
68+
```
69+
70+
Here it says `ReturnCode.Success` which means that the solutuion successfully solved. We can learn more about the different return codes at
71+
[the ReturnCode part of the SciMLBase documentation](https://docs.sciml.ai/SciMLBase/stable/interfaces/Solutions/#retcodes).
72+
73+
If we are interested about some of the statistics of the solving process, for example to help choose a better solver, we can investigate the `sol.stats`
74+
75+
```@example intro
76+
sol.stats
77+
```
78+
79+
That's just a bit of what's in there, check out the other pages for more information but now let's move onto customization.
80+
2081
## Import a different solver package and solve the problem
2182

2283
OptimizationOptimJL is a wrapper for [Optim.jl](https://github.com/JuliaNLSolvers/Optim.jl) and OptimizationBBO is a wrapper for [BlackBoxOptim.jl](https://github.com/robertfeldt/BlackBoxOptim.jl).

0 commit comments

Comments
 (0)