Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stable version of library working with current examples #119

Merged
merged 30 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
8f88211
Update Project with new dependencies
facusapienza21 Apr 10, 2024
ad54394
remove FiniteDifferences from dependencies
facusapienza21 Apr 17, 2024
a4790d3
Example of APWP fit based on Jupp1987
facusapienza21 Apr 17, 2024
29b8c78
add complex-step method
facusapienza21 Apr 19, 2024
a3852d1
Double differentiation working with complex-step method
facusapienza21 Apr 19, 2024
cc5ce31
Initial condition u0 fitting implemented
facusapienza21 Apr 19, 2024
92f00d6
Projected gradient descent working for u0. Some more tests
facusapienza21 Apr 20, 2024
c69a059
Testing activation functions with complex-step
facusapienza21 Apr 29, 2024
6ddd80a
Merge branch 'main' into main
facusapienza21 Apr 29, 2024
ba41e79
Merge branch 'ODINN-SciML:main' into main
facusapienza21 Apr 30, 2024
3e30160
predict function, return multiple losses
facusapienza21 Apr 30, 2024
9413263
Merge branch 'main' of https://github.com/facusapienza21/SphereUDE.jl…
facusapienza21 Apr 30, 2024
10ae8cd
Co-authored-by: Jordi Bolibar <jordi.bolibar@gmail.com>
facusapienza21 Apr 30, 2024
684621f
Merge branch 'main' of https://github.com/facusapienza21/SphereUDE.jl…
facusapienza21 May 3, 2024
3d52691
Multiple shooting working once sensealg specified
facusapienza21 May 3, 2024
9fa3354
Double rotation example with small changes in src
facusapienza21 Jul 20, 2024
e2116c3
feat: update to support Lux 1.0
avik-pal Sep 21, 2024
f4eee7a
Example with double rotation working with non-updated Lux
facusapienza21 Sep 26, 2024
8a01ca5
Integration test of inversion
facusapienza21 Sep 26, 2024
8ee17ed
Added Random as test dependency
facusapienza21 Sep 26, 2024
b92e58a
Merge branch 'main' of https://github.com/facusapienza21/SphereUDE.jl…
facusapienza21 Sep 27, 2024
12a692d
bring changes from @avik-pal branch
facusapienza21 Sep 27, 2024
aad95b4
Fix Lux version
facusapienza21 Sep 27, 2024
b747f84
Merge branch 'ODINN-SciML:main' into main
facusapienza21 Sep 29, 2024
0e66cdb
Merge branch 'main' of https://github.com/facusapienza21/SphereUDE.jl…
facusapienza21 Oct 12, 2024
f7c85f4
Reorganization of loss function in different module
facusapienza21 Oct 14, 2024
f22f809
Implementation of cubic splines as Jupp 1987
facusapienza21 Oct 18, 2024
dd1dc65
Curl examples and reweighted loss experiment
facusapienza21 Oct 29, 2024
ee48555
minimal changes
facusapienza21 Nov 6, 2024
4610185
Bump version
facusapienza21 Nov 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SphereUDE"
uuid = "d7416ba7-148a-4110-b27d-9087fcebab2d"
authors = ["Facundo Sapienza <fsapienza@berkeley.edu>", "Jordi Bolibar <jordi.bolibar@gmail.com>"]
version = "0.1.2"
version = "0.1.3"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
90 changes: 90 additions & 0 deletions examples/Torsvik_2012/Gondwana.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Pkg; Pkg.activate(".")
using Revise
using Lux

using LinearAlgebra, Statistics, Distributions
using SciMLSensitivity
# using OrdinaryDiffEqCore, OrdinaryDiffEqTsit5
using Optimization, OptimizationOptimisers, OptimizationOptimJL

using SphereUDE

# Random seed
using Random
rng = Random.default_rng()
Random.seed!(rng, 613)

using DataFrames, CSV
using Serialization, JLD2

df = CSV.read("./examples/Torsvik_2012/Torsvik-etal-2012_dataset.csv", DataFrame, delim=",")

# Filter the plates that were once part of the supercontinent Gondwana

Gondwana = ["Amazonia", "Parana", "Colorado", "Southern_Africa",
"East_Antarctica", "Madagascar", "Patagonia", "Northeast_Africa",
"Northwest_Africa", "Somalia", "Arabia", "East_Gondwana"]

df = filter(row -> row.Plate ∈ Gondwana, df)
df.Times = df.Age .+= rand(sampler(Normal(0,0.1)), nrow(df)) # Needs to fix this!

df = sort(df, :Times)
times = df.Times

# Fill missing values
df.RLat .= coalesce.(df.RLat, df.Lat)
df.RLon .= coalesce.(df.RLon, df.Lon)

X = sph2cart(Matrix(df[:,["RLat","RLon"]])'; radians=false)

# Retrieve uncertanties from poles and convert α95 into κ
kappas = (140.0 ./ df.a95).^2

data = SphereData(times=times, directions=X, kappas=kappas, L=nothing)

# Training

# Expected maximum angular deviation in one unit of time (degrees)
Δω₀ = 1.5
# Angular velocity
ω₀ = Δω₀ * π / 180.0

tspan = [times[begin], times[end]]

# params = SphereParameters(tmin = tspan[1], tmax = tspan[2],
# reg = [Regularization(order=1, power=2.0, λ=1e5, diff_mode=FiniteDifferences(1e-4))],
# # reg = nothing,
# pretrain = false,
# u0 = [0.0, 0.0, -1.0], ωmax = ω₀,
# reltol = 1e-6, abstol = 1e-6,
# niter_ADAM = 5000, niter_LBFGS = 5000,
# sensealg = InterpolatingAdjoint(autojacvec = ReverseDiffVJP(true)))
params = SphereParameters(tmin = tspan[1], tmax = tspan[2],
reg = [Regularization(order=1, power=2.0, λ=1.0, diff_mode=FiniteDifferences(1e-4))],
# reg = nothing,
pretrain = false,
u0 = [0.0, 0.0, -1.0], ωmax = ω₀,
reltol = 1e-6, abstol = 1e-6,
niter_ADAM = 2000, niter_LBFGS = 2000,
sensealg = InterpolatingAdjoint(autojacvec = ReverseDiffVJP(true)),
hyperparameter_balance = true)


init_bias(rng, in_dims) = LinRange(tspan[1], tspan[2], in_dims)
init_weight(rng, out_dims, in_dims) = 0.1 * ones(out_dims, in_dims)

# Customized neural network to similate weighted moving window in L
U = Lux.Chain(
Lux.Dense(1, 200, rbf, init_bias=init_bias, init_weight=init_weight, use_bias=true),
Lux.Dense(200,10, gelu),
Lux.Dense(10, 3, Base.Fix2(sigmoid_cap, params.ωmax), use_bias=false)
)

results = train(data, params, rng, nothing, U)
results_dict = convert2dict(data, results)


# JLD2.@save "examples/Torsvik_2012/results/results_dict.jld2" results_dict

plot_sphere(data, results, -30., 0., saveas="examples/Torsvik_2012/plots/plot_sphere.pdf", title="Double rotation")
plot_L(data, results, saveas="examples/Torsvik_2012/plots/plot_L.pdf", title="Double rotation")
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ df = CSV.read("./examples/Torsvik_2012/Torsvik-etal-2012_dataset.csv", DataFrame

# Filter the plates that were once part of the supercontinent Gondwana

Gondwana = ["Amazonia", "Parana", "Colorado", "Southern_Africa",
"East_Antarctica", "Madagascar", "Patagonia", "Northeast_Africa",
"Northwest_Africa", "Somalia", "Arabia", "East_Gondwana"]
Laurentia = ["north_america", "greenland"]

df = filter(row -> row.Plate ∈ Gondwana, df)
df = filter(row -> row.Plate ∈ Laurentia, df)
df.Times = df.Age .+= rand(sampler(Normal(0,0.1)), nrow(df)) # Needs to fix this!

df = sort(df, :Times)
Expand All @@ -52,7 +50,7 @@ data = SphereData(times=times, directions=X, kappas=kappas, L=nothing)
tspan = [times[begin], times[end]]

params = SphereParameters(tmin = tspan[1], tmax = tspan[2],
reg = [Regularization(order=1, power=2.0, λ=1e5, diff_mode=FiniteDifferences(1e-4))],
reg = [Regularization(order=1, power=2.0, λ=1e6, diff_mode=FiniteDifferences(1e-4))],
# reg = nothing,
pretrain = false,
u0 = [0.0, 0.0, -1.0], ωmax = ω₀,
Expand All @@ -74,10 +72,8 @@ U = Lux.Chain(
results = train(data, params, rng, nothing, U)
results_dict = convert2dict(data, results)

# JLD2.@save "examples/Torsvik_2012/results/data.jld2" data
# JLD2.@save "examples/Torsvik_2012/results/results.jld2" results
JLD2.@save "examples/Torsvik_2012/results/results_dict.jld2" results_dict

# JLD2.@save "examples/Torsvik_2012/results/results_dict.jld2" results_dict

plot_sphere(data, results, -30., 0., saveas="examples/Torsvik_2012/plots/plot_sphere.pdf", title="Double rotation")
plot_L(data, results, saveas="examples/Torsvik_2012/plots/plot_L.pdf", title="Double rotation")
plot_sphere(data, results, -30., 0., saveas="examples/Torsvik_2012/plots/Laurentia_plot_sphere.pdf", title="Double rotation")
plot_L(data, results, saveas="examples/Torsvik_2012/plots/Laurentia_plot_L.pdf", title="Double rotation")
Loading
Loading