Skip to content

Commit 00ace76

Browse files
committed
Full test of Optim interface
1 parent 3013549 commit 00ace76

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

test/test_optim.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11
using DynamicExpressions, Optim, Zygote
22
using Random: Xoshiro
33

4-
operators = OperatorEnum(; binary_operators=(+, -, *, /), unary_operators=(sin, cos))
4+
operators = OperatorEnum(; binary_operators=(+, -, *, /), unary_operators=(exp,))
55
x1, x2, x3 = (i -> Node(Float64; feature=i)).(1:3);
66

7-
X = randn(Xoshiro(0), Float64, 3, 100);
8-
y = @. cos(X[1, :] * 2.1 - 0.9) + X[3, :] * -0.9
7+
X = rand(Xoshiro(0), Float64, 3, 100);
8+
y = @. exp(X[1, :] * 2.1 - 0.9) + X[3, :] * -0.9
99

10-
original_tree = cos(x1 * 0.8 - 0.0) + 5.2 * x3
10+
original_tree = exp(x1 * 0.8 - 0.0) + 5.2 * x3
11+
target_tree = exp(x1 * 2.1 - 0.9) + -0.9 * x3
1112
tree = copy(original_tree)
1213

1314
res = optimize(t -> sum(abs2, t(X, operators) .- y), tree)
1415

1516
# Should be unchanged by default
17+
if VERSION >= v"1.9"
18+
ext = Base.get_extension(DynamicExpressions, :DynamicExpressionsOptimExt)
19+
@test res isa ext.ExpressionOptimizationResults
20+
end
1621
@test tree == original_tree
22+
@test get_constants(res.minimizer) get_constants(target_tree)

0 commit comments

Comments
 (0)