|
1 |
| -using Test, Flux |
2 |
| - |
3 | 1 | @testset "DeepONet" begin
|
4 |
| - @testset "dimensions" begin |
5 |
| - # Test the proper construction |
| 2 | + @testset "proper construction" begin |
| 3 | + deeponet = DeepONet((32,64,72), (24,48,72), σ, tanh) |
6 | 4 | # Branch net
|
7 |
| - @test size(DeepONet((32,64,72), (24,48,72), σ, tanh).branch_net.layers[end].weight) == (72,64) |
8 |
| - @test size(DeepONet((32,64,72), (24,48,72), σ, tanh).branch_net.layers[end].bias) == (72,) |
| 5 | + @test size(deeponet.branch_net.layers[end].weight) == (72,64) |
| 6 | + @test size(deeponet.branch_net.layers[end].bias) == (72,) |
9 | 7 | # Trunk net
|
10 |
| - @test size(DeepONet((32,64,72), (24,48,72), σ, tanh).trunk_net.layers[end].weight) == (72,48) |
11 |
| - @test size(DeepONet((32,64,72), (24,48,72), σ, tanh).trunk_net.layers[end].bias) == (72,) |
| 8 | + @test size(deeponet.trunk_net.layers[end].weight) == (72,48) |
| 9 | + @test size(deeponet.trunk_net.layers[end].bias) == (72,) |
12 | 10 | end
|
13 | 11 |
|
14 | 12 | # Accept only Int as architecture parameters
|
15 | 13 | @test_throws MethodError DeepONet((32.5,64,72), (24,48,72), σ, tanh)
|
16 | 14 | @test_throws MethodError DeepONet((32,64,72), (24.1,48,72))
|
17 |
| -end |
18 |
| - |
19 |
| -#Just the first 16 datapoints from the Burgers' equation dataset |
20 |
| -a = [0.83541104, 0.83479851, 0.83404712, 0.83315711, 0.83212979, 0.83096755, 0.82967374, 0.82825263, 0.82670928, 0.82504949, 0.82327962, 0.82140651, 0.81943734, 0.81737952, 0.8152405, 0.81302771] |
21 |
| -sensors = collect(range(0, 1, length=16))' |
22 |
| - |
23 |
| -model = DeepONet((16, 22, 30), (1, 16, 24, 30), σ, tanh; init_branch=Flux.glorot_normal, bias_trunk=false) |
24 |
| - |
25 |
| -model(a,sensors) |
26 | 15 |
|
27 |
| -#forward pass |
28 |
| -@test size(model(a, sensors)) == (1, 16) |
29 |
| - |
30 |
| -mgrad = Flux.Zygote.gradient((x,p)->sum(model(x,p)),a,sensors) |
31 |
| - |
32 |
| -#gradients |
33 |
| -@test !iszero(Flux.Zygote.gradient((x,p)->sum(model(x,p)),a,sensors)[1]) |
34 |
| -@test !iszero(Flux.Zygote.gradient((x,p)->sum(model(x,p)),a,sensors)[2]) |
35 |
| - |
36 |
| -#Output size of branch and trunk subnets should be same |
37 |
| -branch = Chain(Dense(16, 22), Dense(22, 30)) |
38 |
| -trunk = Chain(Dense(1, 16), Dense(16, 24), Dense(24, 32)) |
39 |
| -m = DeepONet(branch, trunk) |
40 |
| -@test_throws AssertionError DeepONet((32,64,70), (24,48,72), σ, tanh) |
41 |
| -@test_throws DimensionMismatch m(a, sensors) |
| 16 | + # Just the first 16 datapoints from the Burgers' equation dataset |
| 17 | + a = [0.83541104, 0.83479851, 0.83404712, 0.83315711, 0.83212979, 0.83096755, |
| 18 | + 0.82967374, 0.82825263, 0.82670928, 0.82504949, 0.82327962, 0.82140651, |
| 19 | + 0.81943734, 0.81737952, 0.8152405, 0.81302771] |
| 20 | + sensors = collect(range(0, 1, length=16)') |
| 21 | + model = DeepONet((16, 22, 30), (1, 16, 24, 30), σ, tanh; init_branch=Flux.glorot_normal, bias_trunk=false) |
| 22 | + y = model(a, sensors) |
| 23 | + @test size(y) == (1, 16) |
| 24 | + |
| 25 | + mgrad = Flux.Zygote.gradient(() -> sum(model(a, sensors)), Flux.params(model)) |
| 26 | + @test length(mgrad.grads) == 7 |
| 27 | + |
| 28 | + # Output size of branch and trunk subnets should be same |
| 29 | + branch = Chain(Dense(16, 22), Dense(22, 30)) |
| 30 | + trunk = Chain(Dense(1, 16), Dense(16, 24), Dense(24, 32)) |
| 31 | + m = DeepONet(branch, trunk) |
| 32 | + @test_throws AssertionError DeepONet((32,64,70), (24,48,72), σ, tanh) |
| 33 | + @test_throws DimensionMismatch m(a, sensors) |
| 34 | +end |
0 commit comments