@@ -25,39 +25,37 @@ Currently, `FourierOperator` is provided in this work.
25
25
## Usage
26
26
27
27
``` 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
+ )
47
41
```
48
42
49
43
Or you can just call:
50
44
51
45
``` julia
52
- fno = FourierNeuralOperator ()
46
+ model = FourierNeuralOperator (
47
+ ch= (2 , 64 , 64 , 64 , 64 , 64 , 128 , 1 ),
48
+ modes= (16 , ),
49
+ σ= gelu
50
+ )
53
51
```
54
52
55
53
And then train as a Flux model.
56
54
57
55
``` julia
58
- loss (𝐱, 𝐲) = sum (abs2, 𝐲 .- fno (𝐱)) / size (𝐱)[end ]
56
+ loss (𝐱, 𝐲) = sum (abs2, 𝐲 .- model (𝐱)) / size (𝐱)[end ]
59
57
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)
61
59
```
62
60
63
61
## Examples
@@ -66,7 +64,14 @@ PDE training examples are provided in `example` folder.
66
64
67
65
### One-dimensional Burgers' equation
68
66
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
+ ```
70
75
71
76
### Two-dimensional Darcy flow equation
72
77
0 commit comments