diff --git a/lib/DataDrivenSR/Project.toml b/lib/DataDrivenSR/Project.toml index ecc755c8c..f6b6b6ba5 100644 --- a/lib/DataDrivenSR/Project.toml +++ b/lib/DataDrivenSR/Project.toml @@ -11,7 +11,7 @@ SymbolicRegression = "8254be44-1295-4e6a-a16d-46603ac705cb" [compat] Reexport = "1.2" DataDrivenDiffEq = "1" -SymbolicRegression = "0.17" +SymbolicRegression = "1" julia = "1.6" [extras] diff --git a/lib/DataDrivenSR/src/DataDrivenSR.jl b/lib/DataDrivenSR/src/DataDrivenSR.jl index 6b0ba54dd..70944b286 100644 --- a/lib/DataDrivenSR/src/DataDrivenSR.jl +++ b/lib/DataDrivenSR/src/DataDrivenSR.jl @@ -22,7 +22,7 @@ using Reexport """ $(TYPEDEF) Options for using SymbolicRegression.jl within the `solve` function. -Automatically creates [`Options`](https://astroautomata.com/SymbolicRegression.jl/stable/api/#Options) with the given specification. +Automatically creates [`Options`](https://ai.damtp.cam.ac.uk/symbolicregression/stable/api/#Options) with the given specification. Sorts the operators stored in `functions` into unary and binary operators on conversion. # Fields $(FIELDS) @@ -30,7 +30,7 @@ $(FIELDS) @with_kw struct EQSearch <: AbstractDataDrivenAlgorithm "Optionally weight the loss for each y by this value (same shape as y)" weights::Union{AbstractMatrix, AbstractVector, Nothing} = nothing - "The number of processes to use, if you want EquationSearch to set this up automatically." + "The number of processes to use, if you want `equation_search` to set this up automatically." numprocs = nothing "If you have set up a distributed run manually with procs = addprocs() and @everywhere, pass the procs to this keyword argument." procs::Union{Vector{Int}, Nothing} = nothing @@ -40,7 +40,7 @@ $(FIELDS) parallelism::Union{String, Symbol} = :serial "Whether to run (quick) tests before starting the search, to see if there will be any problems during the equation search related to the host environment" runtests::Bool = true - "Options for 'EquationSearch'" + "Options for `equation_search`" eq_options::SymbolicRegression.Options = SymbolicRegression.Options() end @@ -184,7 +184,7 @@ function (x::EQSearch)(ps::InternalDataDrivenProblem{EQSearch}, X, Y) @unpack maxiters, abstol = options @unpack weights, eq_options, numprocs, procs, parallelism, runtests = x - hofs = SymbolicRegression.EquationSearch(X, Y, + hofs = SymbolicRegression.equation_search(X, Y; niterations = maxiters, weights = weights, options = eq_options, @@ -197,7 +197,7 @@ function (x::EQSearch)(ps::InternalDataDrivenProblem{EQSearch}, X, Y) # Evaluate over the full training data paretos = map(enumerate(hofs)) do (i, hof) - SymbolicRegression.calculate_pareto_frontier(X, Y[i, :], hof, eq_options) + SymbolicRegression.calculate_pareto_frontier(hof) end return SRResult(ps, hofs, paretos) diff --git a/lib/DataDrivenSR/test/runtests.jl b/lib/DataDrivenSR/test/runtests.jl index 7a402f9a1..320ec990e 100644 --- a/lib/DataDrivenSR/test/runtests.jl +++ b/lib/DataDrivenSR/test/runtests.jl @@ -9,6 +9,7 @@ X = rand(rng, 2, 50) @testset "Simple" begin alg = DataDrivenSR.EQSearch(eq_options = Options(unary_operators = [sin, exp], binary_operators = [*], maxdepth = 1, + seed = 42, verbosity = -1, progress = false)) f(x) = [sin(x[1]); exp(x[2])] Y = hcat(map(f, eachcol(X))...) @@ -21,6 +22,7 @@ end @testset "Univariate" begin alg = DataDrivenSR.EQSearch(eq_options = Options(unary_operators = [sin, exp], binary_operators = [*], maxdepth = 1, + seed = 42, verbosity = -1, progress = false)) Y = sin.(X[1:1, :]) @@ -33,6 +35,7 @@ end @testset "Lifted" begin alg = DataDrivenSR.EQSearch(eq_options = Options(unary_operators = [sin, exp], binary_operators = [+], maxdepth = 1, + seed = 42, verbosity = -1, progress = false)) f(x) = [sin(x[1] .^ 2); exp(x[2] * x[1])] diff --git a/lib/DataDrivenSparse/src/DataDrivenSparse.jl b/lib/DataDrivenSparse/src/DataDrivenSparse.jl index 024580fdf..5fc7f7351 100644 --- a/lib/DataDrivenSparse/src/DataDrivenSparse.jl +++ b/lib/DataDrivenSparse/src/DataDrivenSparse.jl @@ -25,8 +25,7 @@ abstract type AbstractProximalOperator end abstract type AbstractSparseRegressionCache <: StatsBase.StatisticalModel end -function _set!(x::AbstractSparseRegressionCache, - y::AbstractSparseRegressionCache) where {T <: Number} +function _set!(x::AbstractSparseRegressionCache, y::AbstractSparseRegressionCache) begin foreach(eachindex(x.X)) do i x.X[i] = y.X[i] diff --git a/lib/DataDrivenSparse/test/sparse_linear_solve.jl b/lib/DataDrivenSparse/test/sparse_linear_solve.jl index 6bccfcb4a..3dddb94ba 100644 --- a/lib/DataDrivenSparse/test/sparse_linear_solve.jl +++ b/lib/DataDrivenSparse/test/sparse_linear_solve.jl @@ -64,8 +64,8 @@ end cos.(0.5 .* t .^ 2 .- 0.1), exp.(-t)))) Y = permutedims(0.5 * X[1, :] + 0.22 * X[4, :] - 2.0 * X[3, :]) X = vcat(X, Y) - for alg in [STLSQ, ADMM, SR3] - opt = ImplicitOptimizer(alg()) + for alg in [STLSQ(0.1, 1.0), ADMM(), SR3()] + opt = ImplicitOptimizer(alg) rescoeff, _... = opt(X, Y, options = DataDrivenCommonOptions(maxiters = 2000)) @test vec(rescoeff)≈[0.25; 0.0; -1.0; 0.11; 0.0; -0.5] atol=5e-2 end diff --git a/src/utils/build_basis.jl b/src/utils/build_basis.jl index 31d3cabc2..eae6a2d7e 100644 --- a/src/utils/build_basis.jl +++ b/src/utils/build_basis.jl @@ -102,7 +102,7 @@ function _implicit_build_eqs(basis, eqs, p, prob) eqs = eqs .~ 0 try # Try to solve the eq for the implicits - eqs = ModelingToolkit.solve_for(eqs, implicits) + eqs = ModelingToolkit.symbolic_linear_solve(eqs, implicits) eqs = implicits .~ eqs implicits = Num[] catch