Skip to content

Commit 2a341dc

Browse files
committed
increase coverage and change authors
1 parent 2f1f4de commit 2a341dc

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

Project.toml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ReliabilityOptimization"
22
uuid = "55eddd50-7f45-4398-96cf-6a37e2b16f80"
3-
authors = ["LucasMSpereira"]
3+
authors = ["Lucas Pereira and Mohamed Tarek"]
44
version = "0.2.0"
55

66
[deps]
@@ -34,8 +34,7 @@ Zygote = "0.6"
3434
julia = "1"
3535

3636
[extras]
37-
FiniteDifferences = "26cc04aa-876d-5657-8c51-4c34ba976000"
3837
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3938

4039
[targets]
41-
test = ["FiniteDifferences", "Test"]
40+
test = ["Test"]

src/ReliabilityOptimization.jl

-6
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,6 @@ end
8585
_vec(x::Real) = [x]
8686
_vec(x) = x
8787

88-
function get_identity_vecs(M)
89-
return [Vector(sparsevec([i], [1.0], M)) for i in 1:M]
90-
end
91-
function ChainRulesCore.rrule(::typeof(get_identity_vecs), M::Int)
92-
get_identity_vecs(M), _ -> (NoTangent(), NoTangent())
93-
end
9488
reduce_hcat(vs) = reduce(hcat, vs)
9589

9690
const fdm = FiniteDifferences.central_fdm(5, 1)

test/runtests.jl

+20-15
Original file line numberDiff line numberDiff line change
@@ -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
2126
end

0 commit comments

Comments
 (0)