Skip to content

Commit

Permalink
run without linesearch by default in newton solver (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed May 16, 2016
1 parent caaba34 commit 65d1205
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ therefore:

```jl
nlsolve(not_in_place(f), initial_x)
```
```

Finite-differencing is used to compute the Jacobian in that case.

Expand Down Expand Up @@ -260,16 +260,15 @@ This method accepts the following custom parameters:

## Newton method with linesearch

This is the classical Newton algorithm with linesearch.
This is the classical Newton algorithm with optional linesearch.

This method is selected with `method = :newton`.

This method accepts a custom parameter `linesearch!`, which must be equal to a
function computing the linesearch. Currently, available values are taken from
the `Optim` package, and are: `Optim.backtracking_linesearch!` (the default),
`Optim.hz_linesearch!`, `Optim.interpolating_linesearch!`. To run without
linesearch, pass the `NLsolve.no_linesearch!` function as argument. **Note:**
it is assumed that a passed linesearch function will at least update the solution
the `Optim` package, and are: `Optim.backtracking_linesearch!`,
`Optim.hz_linesearch!`, `Optim.interpolating_linesearch!`. By default, no linesearch is performed.
**Note:** it is assumed that a passed linesearch function will at least update the solution
vector and evaluate the function at the new point.

## Common options
Expand Down
6 changes: 3 additions & 3 deletions src/nlsolve_func_defs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function nlsolve{T}(df::AbstractDifferentiableMultivariateFunction,
store_trace::Bool = false,
show_trace::Bool = false,
extended_trace::Bool = false,
linesearch!::Function = Optim.backtracking_linesearch!,
linesearch!::Function = no_linesearch!,
factor::Real = one(T),
autoscale::Bool = true)
if extended_trace
Expand Down Expand Up @@ -39,7 +39,7 @@ function nlsolve{T}(f!::Function,
store_trace::Bool = false,
show_trace::Bool = false,
extended_trace::Bool = false,
linesearch!::Function = Optim.backtracking_linesearch!,
linesearch!::Function = no_linesearch!,
factor::Real = one(T),
autoscale::Bool = true)
nlsolve(DifferentiableMultivariateFunction(f!, g!),
Expand All @@ -58,7 +58,7 @@ function nlsolve{T}(f!::Function,
store_trace::Bool = false,
show_trace::Bool = false,
extended_trace::Bool = false,
linesearch!::Function = Optim.backtracking_linesearch!,
linesearch!::Function = no_linesearch!,
factor::Real = one(T),
autoscale::Bool = true,
autodiff::Bool = false)
Expand Down
4 changes: 2 additions & 2 deletions test/minpack.jl
Original file line number Diff line number Diff line change
Expand Up @@ -511,14 +511,14 @@ for (df, initial, name) in alltests
if method == :newton && name in TESTS_FAIL_NEWTON
continue
end
tot_time = @elapsed r = nlsolve(df, initial, method = method)
tot_time = @elapsed r = nlsolve(df, initial, method = method, linesearch! = Optim.backtracking_linesearch!)
@printf("%-45s %5d %5d %5d %14e %10e\n", name*"-"*string(method), length(initial),
r.f_calls, r.g_calls, r.residual_norm, tot_time)
@test converged(r)
@printf(f_out, "%-45s %5d %5d %5d %14e\n", name*"-"*string(method), length(initial),
r.f_calls, r.g_calls, r.residual_norm)
# with autodiff
tot_time = @elapsed r_AD = nlsolve(df.f!, initial, method = method, autodiff = true)
tot_time = @elapsed r_AD = nlsolve(df.f!, initial, method = method, autodiff = true, linesearch! = Optim.backtracking_linesearch!)
@printf("%-45s %5d %5d %5d %14e %10e\n", name*"-"*string(method)*"-AD",
length(initial), r_AD.f_calls, r_AD.g_calls, r_AD.residual_norm, tot_time)
@printf(f_out, "%-45s %5d %5d %5d %14e\n", name*"-"*string(method)*"-AD", length(initial),
Expand Down

0 comments on commit 65d1205

Please sign in to comment.