@@ -2,20 +2,25 @@ using ReliabilityOptimization, Test, FiniteDifferences, Zygote
22
33@testset " ReliabilityOptimization.jl" begin
44 # test function - y is random
5- pol (x, y) = [norm (x + y)^ 2 ]
6- # input value to be used in example
7- x = [2.0 , 3.0 , 6.0 ]
8- # wrap original function in RandomFunction struct
9- y = MvNormal (zeros (3 ), Diagonal (ones (3 )))
10- rf = RandomFunction (pol, y, FORM (RIA ()))
11- # call wrapper with example input
12- d = rf (x)
13- function obj (x)
14- dist = rf (x)
15- mean (dist)[1 ] + 2 * sqrt (cov (dist)[1 , 1 ])
5+ for pol in [
6+ (x, y) -> [norm (x + y)^ 2 ],
7+ (x, y) -> norm (x + y)^ 2
8+ ]
9+ # input value to be used in example
10+ x = [2.0 , 3.0 , 6.0 ]
11+ # wrap original function in RandomFunction struct
12+ y = MvNormal (zeros (3 ), Diagonal (ones (3 )))
13+ rf = RandomFunction (pol, y)
14+ rf = RandomFunction (pol, y, FORM (RIA ()))
15+ # call wrapper with example input
16+ d = rf (x)
17+ function obj (x)
18+ dist = rf (x)
19+ mean (dist)[1 ] + 2 * sqrt (cov (dist)[1 , 1 ])
20+ end
21+ obj (x)
22+ g1 = FiniteDifferences. grad (central_fdm (5 , 1 ), obj, x)[1 ]
23+ g2 = Zygote. gradient (obj, x)[1 ]
24+ @test norm (g1 - g2) < 1e-7
1625 end
17- obj (x)
18- g1 = FiniteDifferences. grad (central_fdm (5 , 1 ), obj, x)[1 ]
19- g2 = Zygote. gradient (obj, x)[1 ]
20- @test norm (g1 - g2) < 1e-7
2126end
0 commit comments