-
-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement DeepONet, refactor pinoode
- Loading branch information
1 parent
8a98880
commit 2cc1d1f
Showing
4 changed files
with
237 additions
and
376 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#TODO: Add docstrings | ||
""" | ||
DeepONet(branch,trunk) | ||
""" | ||
struct DeepONet{} <: Lux.AbstractExplicitLayer | ||
branch::Lux.AbstractExplicitLayer | ||
trunk::Lux.AbstractExplicitLayer | ||
end | ||
|
||
function Lux.setup(rng::AbstractRNG, l::DeepONet) | ||
branch, trunk = l.branch, l.trunk | ||
θ_branch, st_branch = Lux.setup(rng, branch) | ||
θ_trunk, st_trunk = Lux.setup(rng, trunk) | ||
θ = (branch = θ_branch, trunk = θ_trunk) | ||
st = (branch = st_branch, trunk = st_trunk) | ||
θ, st | ||
end | ||
|
||
# function Lux.initialparameters(rng::AbstractRNG, e::DeepONet) | ||
# code | ||
# end | ||
|
||
Lux.initialstates(::AbstractRNG, ::DeepONet) = NamedTuple() | ||
|
||
""" | ||
example: | ||
branch = Lux.Chain(Lux.Dense(1, 32, Lux.σ), Lux.Dense(32, 1)) | ||
trunk = Lux.Chain(Lux.Dense(1, 32, Lux.σ), Lux.Dense(32, 1)) | ||
a = rand(1, 100, 10) | ||
t = rand(1, 1, 10) | ||
x = (branch = a, trunk = t) | ||
deeponet = DeepONet(branch, trunk) | ||
θ, st = Lux.setup(Random.default_rng(), deeponet) | ||
y = deeponet(x, θ, st) | ||
""" | ||
@inline function (f::DeepONet)(x::NamedTuple, θ, st::NamedTuple) | ||
parameters, cord = x.branch, x.trunk | ||
branch, trunk = f.branch, f.trunk | ||
st_branch, st_trunk = st.branch, st.trunk | ||
θ_branch, θ_trunk = θ.branch, θ.trunk | ||
out_b, st_b = branch(parameters, θ_branch, st_branch) | ||
out_t, st_t = trunk(cord, θ_trunk, st_trunk) | ||
out = out_b' * out_t | ||
return out, (branch = st_b, trunk = st_t) | ||
end |
Oops, something went wrong.