2017-02-23 22:40:07 +00:00
|
|
|
|
@testset "Basics" begin
|
|
|
|
|
|
|
|
|
|
xs = randn(10)
|
2016-12-15 22:31:39 +00:00
|
|
|
|
d = Affine(10, 20)
|
|
|
|
|
|
2017-01-30 17:08:45 +00:00
|
|
|
|
@test d(xs) ≈ (xs'*d.W.x + d.b.x)[1,:]
|
2016-12-15 23:11:35 +00:00
|
|
|
|
|
2017-03-20 19:57:00 +00:00
|
|
|
|
d1 = @net x -> x * d.W + d.b
|
|
|
|
|
|
|
|
|
|
@test d(xs) == d1(xs)
|
|
|
|
|
|
2016-12-15 23:13:20 +00:00
|
|
|
|
let
|
2017-03-21 01:18:00 +00:00
|
|
|
|
# In 0.6 `.+` evaluates to an anon function, so we must match on that.
|
|
|
|
|
@capture(syntax(d), _Frame(_Line(bplus_(x_[1] * W_, b_))))
|
2017-02-21 15:46:38 +00:00
|
|
|
|
@test isa(x, DataFlow.Input) && isa(W, Param) && isa(b, Param)
|
2016-12-15 23:11:35 +00:00
|
|
|
|
end
|
2017-02-01 12:53:28 +00:00
|
|
|
|
|
|
|
|
|
let a1 = Affine(10, 20), a2 = Affine(20, 15)
|
|
|
|
|
tlp = TLP(a1, a2)
|
|
|
|
|
@test tlp(xs) ≈ softmax(a2(σ(a1(xs))))
|
2017-02-24 14:38:17 +00:00
|
|
|
|
@test Flux.interpmodel(tlp, xs) ≈ softmax(a2(σ(a1(xs))))
|
2017-02-01 14:56:38 +00:00
|
|
|
|
@test Flux.infer(tlp, (1, 10)) == (1,15)
|
2017-02-01 12:53:28 +00:00
|
|
|
|
end
|
2017-02-21 16:34:15 +00:00
|
|
|
|
|
|
|
|
|
let tlp = TLP(Affine(10, 21), Affine(20, 15))
|
|
|
|
|
e = try
|
2017-02-24 14:38:17 +00:00
|
|
|
|
Flux.interpmodel(tlp, rand(10))
|
2017-02-21 16:34:15 +00:00
|
|
|
|
catch e
|
|
|
|
|
e
|
|
|
|
|
end
|
|
|
|
|
@test e.trace[end].func == :TLP
|
|
|
|
|
@test e.trace[end-1].func == Symbol("Flux.Affine")
|
|
|
|
|
end
|
2017-02-23 22:40:07 +00:00
|
|
|
|
|
2017-03-06 16:12:03 +00:00
|
|
|
|
let m = Multi(10, 15)
|
2017-03-30 14:54:42 +00:00
|
|
|
|
x, y = rand(10), rand(10)
|
|
|
|
|
@test all(isapprox.(m(x, y), (m.W.x' * x, m.V.x' * y)))
|
|
|
|
|
@test all(isapprox.(m(x, y), Flux.interpmodel(m, x, y)))
|
2017-03-06 16:12:03 +00:00
|
|
|
|
end
|
|
|
|
|
|
2017-02-23 22:40:07 +00:00
|
|
|
|
end
|