add test for optimizers

This commit is contained in:
ylxdzsw 2017-06-26 17:21:17 +08:00
parent c9ae219613
commit f64dca2df6
2 changed files with 40 additions and 0 deletions

38
test/optimizer.jl Normal file
View File

@ -0,0 +1,38 @@
@testset "training julia models" begin
@testset "linear regression" begin
srand(0)
model = Affine(10, 1)
truth = Float32[0, 4, 2, 2, -3, 6, -1, 3, 2, -5]'
data = map(1:256) do i
x = rand(Float32, 10)
x, truth * x + 3rand(Float32)
end
Flux.train!(model, data, epoch=5)
@test cor(reshape.((model.W.x, truth), 10)...) > .99
end
@testset "logistic regression" begin
srand(0)
model = Chain(Affine(10, 1), σ)
truth = Float32[0, 4, 2, 2, -3, 6, -1, 3, 2, -5]'
data = map(1:256) do i
x = rand(Float32, 10)
x, truth * x + 2rand(Float32) > 5f0
end
Flux.train!(model, data, epoch=10)
@test cor(reshape.((model.layers[1].W.x, truth), 10)...) > .99
end
end

View File

@ -15,5 +15,7 @@ include("backend/common.jl")
include("basic.jl")
include("recurrent.jl")
include("optimizer.jl")
@tfonly include("backend/tensorflow.jl")
@mxonly include("backend/mxnet.jl")