From 0c932e291b0361592ab76b726dcd5604271e8a9a Mon Sep 17 00:00:00 2001 From: Chris Rackauckas Date: Tue, 4 Apr 2023 07:49:21 -0400 Subject: [PATCH] format --- README.md | 1 - src/NeuralPDE.jl | 3 ++- src/ode_solve.jl | 10 ++++++---- src/training_strategies.jl | 6 +++--- test/NNODE_tests.jl | 9 +++++---- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index a0984d51cb..fdf955c4b4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,6 @@ For information on using the package, [in-development documentation](https://docs.sciml.ai/NeuralPDE/dev/) for the version of the documentation, which contains the unreleased features. - ## Features - Physics-Informed Neural Networks for ODE, SDE, RODE, and PDE solving diff --git a/src/NeuralPDE.jl b/src/NeuralPDE.jl index 0c3b221c3d..f61544274f 100644 --- a/src/NeuralPDE.jl +++ b/src/NeuralPDE.jl @@ -52,7 +52,8 @@ export NNODE, TerminalPDEProblem, NNPDEHan, NNPDENS, NNRODE, KolmogorovPDEProblem, NNKolmogorov, NNStopping, ParamKolmogorovPDEProblem, KolmogorovParamDomain, NNParamKolmogorov, PhysicsInformedNN, discretize, - GridTraining, StochasticTraining, QuadratureTraining, QuasiRandomTraining, WeightedIntervalTraining, + GridTraining, StochasticTraining, QuadratureTraining, QuasiRandomTraining, + WeightedIntervalTraining, build_loss_function, get_loss_function, generate_training_sets, get_variables, get_argument, get_bounds, get_phi, get_numeric_derivative, get_numeric_integral, diff --git a/src/ode_solve.jl b/src/ode_solve.jl index 34837a6f56..11f7429a40 100644 --- a/src/ode_solve.jl +++ b/src/ode_solve.jl @@ -284,7 +284,8 @@ function generate_loss(strategy::StochasticTraining, phi, f, autodiff::Bool, tsp optf = OptimizationFunction(loss, Optimization.AutoZygote()) end -function generate_loss(strategy::WeightedIntervalTraining, phi, f, autodiff::Bool, tspan, p, batch) +function generate_loss(strategy::WeightedIntervalTraining, phi, f, autodiff::Bool, tspan, p, + batch) minT = tspan[1] maxT = tspan[2] @@ -297,12 +298,13 @@ function generate_loss(strategy::WeightedIntervalTraining, phi, f, autodiff::Boo data = Float64[] for (index, item) in enumerate(weights) - temp_data = rand(1, trunc(Int, samples * item)) .* difference .+ minT .+ ((index - 1) * difference) + temp_data = rand(1, trunc(Int, samples * item)) .* difference .+ minT .+ + ((index - 1) * difference) data = append!(data, temp_data) end ts = data - + function loss(θ, _) if batch sum(abs2, inner_loss(phi, f, autodiff, ts, θ, p)) @@ -413,7 +415,7 @@ function DiffEqBase.__solve(prob::DiffEqBase.AbstractODEProblem, verbose && println("Current loss is: $l, Iteration: $iteration") l < abstol end - + optprob = OptimizationProblem(optf, init_params) res = solve(optprob, opt; callback, maxiters, alg.kwargs...) diff --git a/src/training_strategies.jl b/src/training_strategies.jl index 9856343ffb..6c6dacbb7a 100644 --- a/src/training_strategies.jl +++ b/src/training_strategies.jl @@ -299,7 +299,6 @@ function get_loss_function(loss_function, lb, ub, eltypeθ, strategy::Quadrature return loss end - """ ```julia WeightedIntervalTraining(weights, samples) @@ -328,7 +327,8 @@ function WeightedIntervalTraining(weights, samples) WeightedIntervalTraining(weights, samples) end -function get_loss_function(loss_function, train_set, eltypeθ, strategy::WeightedIntervalTraining; +function get_loss_function(loss_function, train_set, eltypeθ, + strategy::WeightedIntervalTraining; τ = nothing) loss = (θ) -> mean(abs2, loss_function(train_set, θ)) -end \ No newline at end of file +end diff --git a/test/NNODE_tests.jl b/test/NNODE_tests.jl index bc15a016dd..ffc6d68158 100644 --- a/test/NNODE_tests.jl +++ b/test/NNODE_tests.jl @@ -218,12 +218,13 @@ true_sol = solve(prob_oop, Tsit5(), saveat = 0.01) func = Lux.σ N = 12 chain = Lux.Chain(Lux.Dense(1, N, func), Lux.Dense(N, N, func), Lux.Dense(N, N, func), - Lux.Dense(N, N, func), Lux.Dense(N, length(u0))) + Lux.Dense(N, N, func), Lux.Dense(N, length(u0))) opt = Optimisers.Adam(0.01) weights = [0.7, 0.2, 0.1] samples = 200 -alg = NeuralPDE.NNODE(chain, opt, autodiff = false, strategy = NeuralPDE.WeightedIntervalTraining(weights, samples)) -sol = solve(prob_oop, alg, verbose=true, maxiters = 100000, saveat = 0.01) +alg = NeuralPDE.NNODE(chain, opt, autodiff = false, + strategy = NeuralPDE.WeightedIntervalTraining(weights, samples)) +sol = solve(prob_oop, alg, verbose = true, maxiters = 100000, saveat = 0.01) -@test abs(mean(sol) - mean(true_sol)) < 0.2 \ No newline at end of file +@test abs(mean(sol) - mean(true_sol)) < 0.2