-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if user supplied old style gradients and Hessians and correct i…
…t. (#6) * Check if user supplied old style gradients and Hessians. * Add tests.
- Loading branch information
Showing
5 changed files
with
123 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
__precompile__(true) | ||
|
||
module NLSolversBase | ||
|
||
using Compat | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
@testset "deprecations" begin | ||
|
||
# Test example | ||
function exponential(x::Vector) | ||
return exp((2.0 - x[1])^2) + exp((3.0 - x[2])^2) | ||
end | ||
|
||
function exponential_gradient!(x, storage) | ||
storage[1] = -2.0 * (2.0 - x[1]) * exp((2.0 - x[1])^2) | ||
storage[2] = -2.0 * (3.0 - x[2]) * exp((3.0 - x[2])^2) | ||
end | ||
|
||
function exponential_hessian!(x, storage) | ||
storage[1, 1] = 2.0 * exp((2.0 - x[1])^2) * (2.0 * x[1]^2 - 8.0 * x[1] + 9) | ||
storage[1, 2] = 0.0 | ||
storage[2, 1] = 0.0 | ||
storage[2, 2] = 2.0 * exp((3.0 - x[1])^2) * (2.0 * x[2]^2 - 12.0 * x[2] + 19) | ||
end | ||
|
||
x_seed = [0.0, 0.0] | ||
f_x_seed = 8157.682077608529 | ||
|
||
nd = NonDifferentiable(exponential, x_seed) | ||
@test nd.f == exponential | ||
@test value(nd) == f_x_seed | ||
@test nd.last_x_f == [0.0, 0.0] | ||
@test nd.f_calls == [1] | ||
|
||
od = OnceDifferentiable(exponential, exponential_gradient!, x_seed) | ||
@test od.f == exponential | ||
#@test od.g! == exponential_gradient! | ||
@test value(od) == f_x_seed | ||
@test od.last_x_f == [0.0, 0.0] | ||
@test od.f_calls == [1] | ||
@test od.g_calls == [1] | ||
|
||
td = TwiceDifferentiable(exponential, exponential_gradient!, exponential_hessian!, x_seed) | ||
@test td.f == exponential | ||
#@test td.g! == exponential_gradient! | ||
@test value(td) == f_x_seed | ||
@test td.last_x_f == [0.0, 0.0] | ||
@test td.f_calls == [1] | ||
@test td.g_calls == [1] | ||
@test td.h_calls == [1] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ using Base.Test | |
|
||
include("objective_types.jl") | ||
include("interface.jl") | ||
include("deprecations.jl") |