Skip to content

Commit e5f102f

Browse files
committed
add tests
1 parent e004bef commit e5f102f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/ReinforcementLearningCore/test/utils/networks.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,30 @@ using Flux: params, gradient, unsqueeze
171171
end
172172
end
173173
@testset "CovGaussianNetwork" begin
174+
@testset "utility functions" begin
175+
cholesky_vec = [1:6;]
176+
cholesky_mat = [RLCore.softplusbeta(1) 0 0; 2 RLCore.softplusbeta(4) 0; 3 5 RLCore.softplusbeta(6)]
177+
@test RLCore.vec_to_tril(cholesky_vec, 3) cholesky_mat
178+
for i in 1:3, j in 1:i
179+
inds_mat = [1 0 0; 2 4 0; 3 5 6]
180+
@test RLCore.cholesky_matrix_to_vector_index(i, j, 3) == inds_mat[i,j]
181+
end
182+
for x in -10:10
183+
@test RLCore.softplusbeta(x,1) softplus(x) log(exp(x) +1)
184+
end
185+
for x in -10:10
186+
@test RLCore.softplusbeta(x,2) log(exp(x/2) +1)*2 >= softplus(x)
187+
end
188+
for x in -10:10
189+
@test RLCore.softplusbeta(x,0.5) log(exp(x/0.5) +1)*0.5 <= softplus(x)
190+
end
191+
cholesky_mats = stack([cholesky_mat for _ in 1:5], dims = 3)
192+
cholesky_vecs = stack([reshape(cholesky_vec, :, 1) for _ in 1:5], dims = 3)
193+
@test RLCore.vec_to_tril(cholesky_vecs, 3) cholesky_mats
194+
for i in 1:3
195+
@test RLCore.cholesky_columns(cholesky_vecs, i, 5, 3) reshape(cholesky_mats[:, i, :], 3, 1, :)
196+
end
197+
end
174198
@testset "identity normalizer" begin
175199
pre = Dense(20,15)
176200
μ = Dense(15,10)

0 commit comments

Comments
 (0)