-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding taylor series propagation & tests
- Loading branch information
1 parent
d9c411f
commit ec8a9ed
Showing
9 changed files
with
751 additions
and
1 deletion.
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
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,49 @@ | ||
include("../../external/ADOLC_wrap/src/ADOLC_wrap.jl") | ||
using .ADOLC_wrap.AdoubleModule | ||
using .ADOLC_wrap | ||
|
||
enableMinMaxUsingAbs() | ||
|
||
function func_eval(x) | ||
return (max(-x[1]-x[2], -x[1]-x[2]+x[1]^2+x[2]^2-1) + max(-x[2]-x[3], -x[2]-x[3]+x[2]^2+x[3]^2-1)) | ||
end | ||
|
||
x = [-0.500000, -0.500000, -0.500000] | ||
n = length(x) | ||
y = Vector{Float64}(undef, 1) | ||
m = length(y) | ||
a = [AdoubleCxx() for _ in 1:length(x)] | ||
b = [AdoubleCxx() for _ in 1:length(y)] | ||
|
||
tape_num = 0 | ||
trace_on(tape_num, 1) | ||
a << x | ||
b[1] = func_eval(a) | ||
b >> y | ||
trace_off(0) | ||
|
||
abs_normal_problem = | ||
AbsNormalProblem{Float64}(tape_num, m, n, x, y) | ||
|
||
|
||
abs_normal!(abs_normal_problem, tape_num) | ||
|
||
using Test | ||
@test abs_normal_problem.Y[1, 1] == -1.5 | ||
@test abs_normal_problem.Y[1, 2] == -3.0 | ||
@test abs_normal_problem.Y[1, 3] == -1.5 | ||
|
||
@test abs_normal_problem.J[1, 1] == 0.5 | ||
@test abs_normal_problem.J[1, 2] == 0.5 | ||
|
||
@test abs_normal_problem.Z[1, 1] == -1.0 | ||
@test abs_normal_problem.Z[1, 2] == -1.0 | ||
@test abs_normal_problem.Z[1, 3] == 0.0 | ||
@test abs_normal_problem.Z[2, 1] == 0.0 | ||
@test abs_normal_problem.Z[2, 2] == -1.0 | ||
@test abs_normal_problem.Z[2, 3] == -1.0 | ||
|
||
@test abs_normal_problem.L[1, 1] == 0.0 | ||
@test abs_normal_problem.L[1, 2] == 0.0 | ||
@test abs_normal_problem.L[2, 1] == 0.0 | ||
@test abs_normal_problem.L[2, 2] == 0.0 |
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,76 @@ | ||
include("../src/ADOLC_wrap.jl") | ||
using .ADOLC_wrap | ||
using Test | ||
# Chained LQ | ||
|
||
function chained_lq(x) | ||
return ( | ||
max(-x[1] - x[2], -x[1] - x[2] + x[1]^2 + x[2]^2 - 1) + | ||
max(-x[2] - x[3], -x[2] - x[3] + x[2]^2 + x[3]^2 - 1) | ||
) | ||
end | ||
|
||
x = [0.0, 2.0, -1.0] | ||
g = gradient(chained_lq, x, 1) | ||
|
||
@test g[1]==-1.0 | ||
@test g[2]==6.0 | ||
@test g[3]==-3.0 | ||
|
||
|
||
|
||
################################# reverse mode test ################################### | ||
|
||
|
||
function func(x) | ||
return [ | ||
x[1] * x[2]^3, | ||
x[1] + x[3] / x[2] | ||
] | ||
end | ||
|
||
init_point = [-1.0, 2.0, -1.0] | ||
num_dependent = 2 | ||
Z = gradient(func, init_point, num_dependent, mode=:tape_based) | ||
|
||
@test Z[1, 1] == 8.0 | ||
@test Z[2, 1] == 1.0 | ||
@test Z[1, 2] == -12.0 | ||
@test Z[2, 2] == 0.25 | ||
@test Z[1, 3] == 0.0 | ||
@test Z[2, 3] == 0.5 | ||
|
||
|
||
|
||
|
||
Z = gradient(func, init_point, num_dependent, mode=:tape_based, derivative_order=2) | ||
|
||
|
||
@test Z[1][1, 1, 1] == 8.0 | ||
@test Z[1][1, 2, 1] == -12.0 | ||
@test Z[1][1, 3, 1] == 0.0 | ||
@test Z[1][1, 1, 2] == 0.0 | ||
@test Z[1][1, 2, 2] == 12.0 | ||
@test Z[1][1, 3, 2] == 0.0 | ||
|
||
@test Z[1][2, 1, 1] == 1.0 | ||
@test Z[1][2, 2, 1] == 0.25 | ||
@test Z[1][2, 3, 1] == 0.5 | ||
@test Z[1][2, 1, 2] == 0.0 | ||
@test Z[1][2, 2, 2] == 0.0 | ||
@test Z[1][2, 3, 2] == 0.0 | ||
|
||
|
||
@test Z[2][1, 1, 1] == 8.0 | ||
@test Z[2][1, 2, 1] == -12.0 | ||
@test Z[2][1, 3, 1] == 0.0 | ||
@test Z[2][1, 1, 2] == 12.0 | ||
@test Z[2][1, 2, 2] == -12.0 | ||
@test Z[2][1, 3, 2] == 0.0 | ||
|
||
@test Z[2][2, 1, 1] == 1.0 | ||
@test Z[2][2, 2, 1] == 0.25 | ||
@test Z[2][2, 3, 1] == 0.5 | ||
@test Z[2][2, 1, 2] == 0.0 | ||
@test Z[2][2, 2, 2] == | ||
@test Z[2][2, 3, 2] == 0.0 |
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,29 @@ | ||
include("../src/ADOLC_wrap.jl") | ||
using .ADOLC_wrap | ||
using .ADOLC_wrap.TladoubleModule | ||
using .ADOLC_wrap.Adouble | ||
using Test | ||
|
||
# Chained LQ | ||
|
||
function chained_lq(x) | ||
return ( | ||
max(-x[1] - x[2], -x[1] - x[2] + x[1]^2 + x[2]^2 - 1) + | ||
max(-x[2] - x[3], -x[2] - x[3] + x[2]^2 + x[3]^2 - 1) | ||
) | ||
end | ||
|
||
x = [0.0, 2.0, -1.0] | ||
g = Main.gradient(chained_lq, x, 1, switch_point=100) | ||
g1 = Main.gradient(chained_lq, x, 1, switch_point=100, mode=:tape_based) | ||
|
||
|
||
@test g[1]==-1.0 | ||
@test g[2]==6.0 | ||
@test g[3]==-3.0 | ||
|
||
@test g[1]==g1[1] | ||
@test g[2]==g1[2] | ||
@test g[3]==g1[3] | ||
|
||
|
Empty file.
Oops, something went wrong.