Skip to content
This repository was archived by the owner on Sep 28, 2024. It is now read-only.

Commit 6d63cca

Browse files
committed
extend model to a more flexible one
1 parent b79fd32 commit 6d63cca

File tree

2 files changed

+40
-35
lines changed

2 files changed

+40
-35
lines changed

README.md

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,37 @@ Currently, `FourierOperator` is provided in this work.
2525
## Usage
2626

2727
```julia
28-
function FourierNeuralOperator()
29-
modes = (16, )
30-
ch = 64 => 64
31-
σ = gelu
32-
33-
return Chain(
34-
# project finite-dimensional data to infinite-dimensional space
35-
Dense(2, 64),
36-
# operator projects data between infinite-dimensional spaces
37-
FourierOperator(ch, modes, σ),
38-
FourierOperator(ch, modes, σ),
39-
FourierOperator(ch, modes, σ),
40-
FourierOperator(ch, modes),
41-
# project infinite-dimensional function to finite-dimensional space
42-
Dense(64, 128, σ),
43-
Dense(128, 1),
44-
flatten
45-
)
46-
end
28+
model = Chain(
29+
# project finite-dimensional data to infinite-dimensional space
30+
Dense(2, 64),
31+
# operator projects data between infinite-dimensional spaces
32+
FourierOperator(64=>64, (16, ), gelu),
33+
FourierOperator(64=>64, (16, ), gelu),
34+
FourierOperator(64=>64, (16, ), gelu),
35+
FourierOperator(64=>64, (16, )),
36+
# project infinite-dimensional function to finite-dimensional space
37+
Dense(64, 128, gelu),
38+
Dense(128, 1),
39+
flatten
40+
)
4741
```
4842

4943
Or you can just call:
5044

5145
```julia
52-
fno = FourierNeuralOperator()
46+
model = FourierNeuralOperator(
47+
ch=(2, 64, 64, 64, 64, 64, 128, 1),
48+
modes=(16, ),
49+
σ=gelu
50+
)
5351
```
5452

5553
And then train as a Flux model.
5654

5755
```julia
58-
loss(𝐱, 𝐲) = sum(abs2, 𝐲 .- fno(𝐱)) / size(𝐱)[end]
56+
loss(𝐱, 𝐲) = sum(abs2, 𝐲 .- model(𝐱)) / size(𝐱)[end]
5957
opt = Flux.Optimiser(WeightDecay(1f-4), Flux.ADAM(1f-3))
60-
Flux.@epochs 50 Flux.train!(loss, params(m), data, opt)
58+
Flux.@epochs 50 Flux.train!(loss, params(model), data, opt)
6159
```
6260

6361
## Examples
@@ -66,7 +64,14 @@ PDE training examples are provided in `example` folder.
6664

6765
### One-dimensional Burgers' equation
6866

69-
[Burgers' equation](https://en.wikipedia.org/wiki/Burgers%27_equation) example can be found in `example/burgers.jl`.
67+
[Burgers' equation](https://en.wikipedia.org/wiki/Burgers%27_equation) example can be found in `example/Burgers`.
68+
Use following commend to train model:
69+
70+
```julia
71+
$ julia --proj=example/Burgers
72+
73+
julia> using Burgers; Burgers.train()
74+
```
7075

7176
### Two-dimensional Darcy flow equation
7277

src/model.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
export
22
FourierNeuralOperator
33

4-
function FourierNeuralOperator()
5-
modes = (16, )
6-
ch = 64 => 64
7-
σ = gelu
8-
4+
function FourierNeuralOperator(;
5+
ch=(2, 64, 64, 64, 64, 64, 128, 1),
6+
modes=(16, ),
7+
σ=gelu
8+
)
99
return Chain(
10-
Dense(2, 64),
11-
FourierOperator(ch, modes, σ),
12-
FourierOperator(ch, modes, σ),
13-
FourierOperator(ch, modes, σ),
14-
FourierOperator(ch, modes),
15-
Dense(64, 128, σ),
16-
Dense(128, 1),
10+
Dense(ch[1], ch[2]),
11+
FourierOperator(ch[2]=>ch[3], modes, σ),
12+
FourierOperator(ch[3]=>ch[4], modes, σ),
13+
FourierOperator(ch[4]=>ch[5], modes, σ),
14+
FourierOperator(ch[5]=>ch[6], modes),
15+
Dense(ch[6], ch[7], σ),
16+
Dense(ch[7], ch[8]),
1717
flatten
1818
)
1919
end

0 commit comments

Comments
 (0)