diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 700707ced..1e8a051e2 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,3 +5,6 @@ updates: directory: "/" # Location of package manifests schedule: interval: "weekly" + ignore: + - dependency-name: "crate-ci/typos" + update-types: ["version-update:semver-patch"] diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 31ebfc6a9..5cdcaa9ed 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -15,7 +15,6 @@ jobs: - Core version: - '1' - - '1.6' steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v1 diff --git a/.github/workflows/Documentation.yml b/.github/workflows/Documentation.yml index 09c0a315a..31ebb212a 100644 --- a/.github/workflows/Documentation.yml +++ b/.github/workflows/Documentation.yml @@ -16,7 +16,15 @@ jobs: with: version: '1' - name: Install dependencies - run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()' + run: julia --project=docs/ -e 'using Pkg; + Pkg.develop(PackageSpec(path=pwd())); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesAbstractGPs"))); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesFlux"))); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesMOE"))); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesPolyChaos"))); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesRandomForest"))); + Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesSVM"))); + Pkg.instantiate()' - name: Build and deploy env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token diff --git a/.github/workflows/SpellCheck.yml b/.github/workflows/SpellCheck.yml new file mode 100644 index 000000000..74af4eff7 --- /dev/null +++ b/.github/workflows/SpellCheck.yml @@ -0,0 +1,13 @@ +name: Spell Check + +on: [pull_request] + +jobs: + typos-check: + name: Spell Check with Typos + runs-on: ubuntu-latest + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v4 + - name: Check spelling + uses: crate-ci/typos@v1.16.23 \ No newline at end of file diff --git a/.typos.toml b/.typos.toml new file mode 100644 index 000000000..9a032fd3f --- /dev/null +++ b/.typos.toml @@ -0,0 +1,2 @@ +[default.extend-words] +ND = "ND" \ No newline at end of file diff --git a/Project.toml b/Project.toml index f4071d0bb..f6e3274f3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Surrogates" uuid = "6fc51010-71bc-11e9-0e15-a3fcc6593c49" authors = ["SciML"] -version = "6.6.0" +version = "6.8.0" [deps] Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" @@ -21,10 +21,10 @@ Flux = "0.12, 0.13" GLM = "1.3" IterativeSolvers = "0.9" PolyChaos = "0.2" -QuasiMonteCarlo = "=0.2.16" +QuasiMonteCarlo = "0.3" Statistics = "1" Zygote = "0.4, 0.5, 0.6" -julia = "1.6" +julia = "1.9" [extras] Cubature = "667455a9-e2ce-5579-9412-b964f529a492" diff --git a/docs/Project.toml b/docs/Project.toml index be97ce9de..cfb7242a1 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -15,7 +15,7 @@ Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" [compat] AbstractGPs = "0.5.13" -Documenter = "0.27" +Documenter = "1" Flux = "0.13.7, 0.14" Plots = "1.36.2" QuadGK = "2.6.0" diff --git a/docs/make.jl b/docs/make.jl index 5c7f3dc41..2025f4ba3 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -10,17 +10,11 @@ using Plots include("pages.jl") makedocs(sitename = "Surrogates.jl", - strict = [ - :doctest, - :linkcheck, - :parse_error, - :example_block, - # Other available options are - # :autodocs_block, :cross_references, :docs_block, :eval_block, :example_block, :footnote, :meta_block, :missing_docs, :setup_block - ], - format = Documenter.HTML(analytics = "UA-90474609-3", - assets = ["assets/favicon.ico"], - canonical = "https://docs.sciml.ai/Surrogates/stable/"), - pages = pages) + linkcheck = true, + warnonly = [:missing_docs], + format = Documenter.HTML(analytics = "UA-90474609-3", + assets = ["assets/favicon.ico"], + canonical = "https://docs.sciml.ai/Surrogates/stable/"), + pages = pages) deploydocs(repo = "github.com/SciML/Surrogates.jl.git") diff --git a/docs/pages.jl b/docs/pages.jl index 3b1876c4f..f408f3b6f 100644 --- a/docs/pages.jl +++ b/docs/pages.jl @@ -1,40 +1,40 @@ pages = ["index.md" - "Tutorials" => [ - "Basics" => "tutorials.md", - "Radials" => "radials.md", - "Kriging" => "kriging.md", - "Gaussian Process" => "abstractgps.md", - "Lobachevsky" => "lobachevsky.md", - "Linear" => "LinearSurrogate.md", - "InverseDistance" => "InverseDistance.md", - "RandomForest" => "randomforest.md", - "SecondOrderPolynomial" => "secondorderpoly.md", - "NeuralSurrogate" => "neural.md", - "Wendland" => "wendland.md", - "Polynomial Chaos" => "polychaos.md", - "Variable Fidelity" => "variablefidelity.md", - "Gradient Enhanced Kriging" => "gek.md", - "GEKPLS" => "gekpls.md", - "MOE" => "moe.md", - "Parallel Optimization" => "parallel.md" - ] - "User guide" => [ - "Samples" => "samples.md", - "Surrogates" => "surrogate.md", - "Optimization" => "optimizations.md", - ] - "Benchmarks" => [ - "Sphere function" => "sphere_function.md", - "Lp norm" => "lp.md", - "Rosenbrock" => "rosenbrock.md", - "Tensor product" => "tensor_prod.md", - "Cantilever beam" => "cantilever.md", - "Water Flow function" => "water_flow.md", - "Welded beam function" => "welded_beam.md", - "Branin function" => "BraninFunction.md", - "Improved Branin function" => "ImprovedBraninFunction.md", - "Ackley function" => "ackley.md", - "Gramacy & Lee Function" => "gramacylee.md", - "Salustowicz Benchmark" => "Salustowicz.md", - "Multi objective optimization" => "multi_objective_opt.md", - ]] + "Tutorials" => [ + "Basics" => "tutorials.md", + "Radials" => "radials.md", + "Kriging" => "kriging.md", + "Gaussian Process" => "abstractgps.md", + "Lobachevsky" => "lobachevsky.md", + "Linear" => "LinearSurrogate.md", + "InverseDistance" => "InverseDistance.md", + "RandomForest" => "randomforest.md", + "SecondOrderPolynomial" => "secondorderpoly.md", + "NeuralSurrogate" => "neural.md", + "Wendland" => "wendland.md", + "Polynomial Chaos" => "polychaos.md", + "Variable Fidelity" => "variablefidelity.md", + "Gradient Enhanced Kriging" => "gek.md", + "GEKPLS" => "gekpls.md", + "MOE" => "moe.md", + "Parallel Optimization" => "parallel.md", +] + "User guide" => [ + "Samples" => "samples.md", + "Surrogates" => "surrogate.md", + "Optimization" => "optimizations.md", +] + "Benchmarks" => [ + "Sphere function" => "sphere_function.md", + "Lp norm" => "lp.md", + "Rosenbrock" => "rosenbrock.md", + "Tensor product" => "tensor_prod.md", + "Cantilever beam" => "cantilever.md", + "Water Flow function" => "water_flow.md", + "Welded beam function" => "welded_beam.md", + "Branin function" => "BraninFunction.md", + "Improved Branin function" => "ImprovedBraninFunction.md", + "Ackley function" => "ackley.md", + "Gramacy & Lee Function" => "gramacylee.md", + "Salustowicz Benchmark" => "Salustowicz.md", + "Multi objective optimization" => "multi_objective_opt.md", +]] diff --git a/docs/src/InverseDistance.md b/docs/src/InverseDistance.md index 8f64ccd37..f90bc3f29 100644 --- a/docs/src/InverseDistance.md +++ b/docs/src/InverseDistance.md @@ -15,7 +15,7 @@ default() ### Sampling -We choose to sample f in 25 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Low Discrepancy, this can be done by passing `LowDiscrepancySample()` to the `sample` function. +We choose to sample f in 25 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Low Discrepancy, this can be done by passing `HaltonSample()` to the `sample` function. ```@example Inverse_Distance1D f(x) = sin(x) + sin(x)^2 + sin(x)^3 @@ -23,7 +23,7 @@ f(x) = sin(x) + sin(x)^2 + sin(x)^3 n_samples = 25 lower_bound = 0.0 upper_bound = 10.0 -x = sample(n_samples, lower_bound, upper_bound, LowDiscrepancySample(;base=2)) +x = sample(n_samples, lower_bound, upper_bound, HaltonSample()) y = f.(x) scatter(x, y, label="Sampled points", xlims=(lower_bound, upper_bound), legend=:top) diff --git a/docs/src/ackley.md b/docs/src/ackley.md index de312e6e6..3c903c76f 100644 --- a/docs/src/ackley.md +++ b/docs/src/ackley.md @@ -58,7 +58,7 @@ The fit looks good. Let's now see if we are able to find the minimum value using optimization methods: ```@example ackley -surrogate_optimize(ackley,DYCORS(),lb,ub,my_rad,UniformSample()) +surrogate_optimize(ackley,DYCORS(),lb,ub,my_rad,RandomSample()) scatter(x, y, label="Sampled points", xlims=(lb, ub), ylims=(0, 30), legend=:top) plot!(xs, ackley.(xs), label="True function", legend=:top) plot!(xs, my_rad.(xs), label="Radial basis optimized", legend=:top) diff --git a/docs/src/gekpls.md b/docs/src/gekpls.md index 1f9e02286..d76e0a8f2 100644 --- a/docs/src/gekpls.md +++ b/docs/src/gekpls.md @@ -80,7 +80,7 @@ This next example demonstrates how this can be accomplished. y = sphere_function.(x) g = GEKPLS(x, y, grads, n_comp, delta_x, lb, ub, extra_points, initial_theta) x_point, minima = surrogate_optimize(sphere_function, SRBF(), lb, ub, g, - UniformSample(); maxiters = 20, + RandomSample(); maxiters = 20, num_new_samples = 20, needs_gradient = true) println(minima) diff --git a/docs/src/index.md b/docs/src/index.md index 103b2a775..51538ba63 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -107,62 +107,65 @@ my_lobachevsky = LobachevskySurrogate(x,y,lb,ub,alpha=alpha,n=n) value = my_lobachevsky(5.0) #Adding more data points -surrogate_optimize(f,SRBF(),lb,ub,my_lobachevsky,UniformSample()) +surrogate_optimize(f,SRBF(),lb,ub,my_lobachevsky,RandomSample()) #New approximation value = my_lobachevsky(5.0) ``` ## Reproducibility + ```@raw html
The documentation of this SciML package was built using these direct dependencies, ``` + ```@example using Pkg # hide Pkg.status() # hide ``` + ```@raw html
``` + ```@raw html
and using this machine and Julia version. ``` + ```@example using InteractiveUtils # hide versioninfo() # hide ``` + ```@raw html
``` + ```@raw html
A more complete overview of all dependencies and their versions is also provided. ``` + ```@example using Pkg # hide -Pkg.status(;mode = PKGMODE_MANIFEST) # hide +Pkg.status(; mode = PKGMODE_MANIFEST) # hide ``` + ```@raw html
``` -```@raw html -You can also download the -manifest file and the -project file. +using Markdown +version = TOML.parse(read("../../Project.toml", String))["version"] +name = TOML.parse(read("../../Project.toml", String))["name"] +link_manifest = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version * + "/assets/Manifest.toml" +link_project = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version * + "/assets/Project.toml" +Markdown.parse("""You can also download the +[manifest]($link_manifest) +file and the +[project]($link_project) +file. +""") ``` diff --git a/docs/src/moe.md b/docs/src/moe.md index 1a96b7ad1..0bcd432f1 100644 --- a/docs/src/moe.md +++ b/docs/src/moe.md @@ -92,7 +92,7 @@ end lb = [-1.0, -1.0] ub = [1.0, 1.0] n = 150 -x = sample(n, lb, ub, SobolSample()) +x = sample(n, lb, ub, RandomSample()) y = discont_NDIM.(x) x_test = sample(10, lb, ub, GoldenSample()) @@ -110,7 +110,6 @@ rbf = RadialBasis(x, y, lb, ub) rbf_pred_vals = rbf.(x_test) rbf_rmse = rmse(true_vals, rbf_pred_vals) println(rbf_rmse > moe_rmse) - ``` ### Usage Notes - Example With Other Surrogates diff --git a/docs/src/optimizations.md b/docs/src/optimizations.md index 8a248e06f..90b517867 100644 --- a/docs/src/optimizations.md +++ b/docs/src/optimizations.md @@ -28,5 +28,5 @@ surrogate_optimize(obj::Function,sop1::SOP,lb::Number,ub::Number,surrSOP::Abstra To add another optimization method, you just need to define a new SurrogateOptimizationAlgorithm and write its corresponding algorithm, overloading the following: ``` -surrogate_optimize(obj::Function,::NewOptimizatonType,lb,ub,surr::AbstractSurrogate,sample_type::SamplingAlgorithm;maxiters=100,num_new_samples=100) +surrogate_optimize(obj::Function,::NewOptimizationType,lb,ub,surr::AbstractSurrogate,sample_type::SamplingAlgorithm;maxiters=100,num_new_samples=100) ``` diff --git a/docs/src/parallel.md b/docs/src/parallel.md index 2388e1eec..9bff2f4e4 100755 --- a/docs/src/parallel.md +++ b/docs/src/parallel.md @@ -17,24 +17,24 @@ To ensure that points of interest returned by `potential_optimal_points` are suf The following strategies are available for virtual point selection for all optimization algorithms: -- "Minimum Constant Liar (CLmin)": +- "Minimum Constant Liar (MinimumConstantLiar)": - The virtual point is assigned using the lowest known value of the merit function across all evaluated points. -- "Mean Constant Liar (CLmean)": +- "Mean Constant Liar (MeanConstantLiar)": - The virtual point is assigned using the mean of the merit function across all evaluated points. -- "Maximum Constant Liar (CLmax)": +- "Maximum Constant Liar (MaximumConstantLiar)": - The virtual point is assigned using the great known value of the merit function across all evaluated points. For Kriging surrogates, specifically, the above and follow strategies are available: -- "Kriging Believer (KB)": +- "Kriging Believer (KrigingBeliever): - The virtual point is assigned using the mean of the Kriging surrogate at the virtual point. -- "Kriging Believer Upper Bound (KBUB)": +- "Kriging Believer Upper Bound (KrigingBelieverUpperBound)": - The virtual point is assigned using 3$\sigma$ above the mean of the Kriging surrogate at the virtual point. -- "Kriging Believer Lower Bound (KBLB)": +- "Kriging Believer Lower Bound (KrigingBelieverLowerBound)": - The virtual point is assigned using 3$\sigma$ below the mean of the Kriging surrogate at the virtual point. -In general, CLmin and KBLB tend to favor exploitation while CLmax and KBUB tend to favor exploration. CLmean and KB tend to be a compromise between the two. +In general, MinimumConstantLiar and KrigingBelieverLowerBound tend to favor exploitation while MaximumConstantLiar and KrigingBelieverUpperBound tend to favor exploration. MeanConstantLiar and KrigingBeliever tend to be a compromise between the two. ## Examples @@ -50,7 +50,7 @@ y = f.(x) my_k = Kriging(x, y, lb, ub) for _ in 1:10 - new_x, eis = potential_optimal_points(EI(), lb, ub, my_k, SobolSample(), 3, CLmean!) + new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, SobolSample(), 3) add_point!(my_k, new_x, f.(new_x)) end ``` diff --git a/docs/src/polychaos.md b/docs/src/polychaos.md index e8b6d1110..24b368579 100644 --- a/docs/src/polychaos.md +++ b/docs/src/polychaos.md @@ -9,7 +9,7 @@ we are trying to fit. Under the hood, PolyChaos.jl has been used. It is possible to specify a type of polynomial for each dimension of the problem. ### Sampling -We choose to sample f in 25 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Low Discrepancy, this can be done by passing `LowDiscrepancySample()` to the `sample` function. +We choose to sample f in 25 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Low Discrepancy, this can be done by passing `HaltonSample()` to the `sample` function. ```@example polychaos using Surrogates @@ -20,7 +20,7 @@ default() n = 20 lower_bound = 1.0 upper_bound = 6.0 -x = sample(n,lower_bound,upper_bound,LowDiscrepancySample(2)) +x = sample(n,lower_bound,upper_bound,HaltonSample()) f = x -> log(x)*x + sin(x) y = f.(x) scatter(x, y, label="Sampled points", xlims=(lower_bound, upper_bound), legend=:top) diff --git a/docs/src/radials.md b/docs/src/radials.md index 2ed4a98b6..aa88629ff 100644 --- a/docs/src/radials.md +++ b/docs/src/radials.md @@ -141,7 +141,7 @@ This is why its size changes. size(xys) ``` ```@example RadialBasisSurrogateND -surrogate_optimize(booth, SRBF(), lower_bound, upper_bound, radial_basis, UniformSample(), maxiters=50) +surrogate_optimize(booth, SRBF(), lower_bound, upper_bound, radial_basis, RandomSample(), maxiters=50) ``` ```@example RadialBasisSurrogateND size(xys) diff --git a/docs/src/randomforest.md b/docs/src/randomforest.md index bd336a191..8609bb851 100644 --- a/docs/src/randomforest.md +++ b/docs/src/randomforest.md @@ -32,7 +32,7 @@ plot!(f, label="True function", xlims=(lower_bound, upper_bound), legend=:top) With our sampled points we can build the Random forests surrogate using the `RandomForestSurrogate` function. -`randomforest_surrogate` behaves like an ordinary function which we can simply plot. Addtionally you can specify the number of trees created +`randomforest_surrogate` behaves like an ordinary function which we can simply plot. Additionally you can specify the number of trees created using the parameter num_round ```@example RandomForestSurrogate_tutorial diff --git a/docs/src/samples.md b/docs/src/samples.md index 4515c36fa..2a92a9d89 100644 --- a/docs/src/samples.md +++ b/docs/src/samples.md @@ -17,7 +17,7 @@ sample(n,lb,ub,S::GridSample) * Uniform sample ``` -sample(n,lb,ub,::UniformSample) +sample(n,lb,ub,::RandomSample) ``` * Sobol sample @@ -32,8 +32,7 @@ sample(n,lb,ub,::LatinHypercubeSample) * Low Discrepancy sample ``` -LowDiscrepancySample{T} -sample(n,lb,ub,S::LowDiscrepancySample) +sample(n,lb,ub,S::HaltonSample) ``` * Sample on section diff --git a/docs/src/secondorderpoly.md b/docs/src/secondorderpoly.md index ef2329986..97826e852 100644 --- a/docs/src/secondorderpoly.md +++ b/docs/src/secondorderpoly.md @@ -18,7 +18,7 @@ f = x -> 3*sin(x) + 10/x lb = 3.0 ub = 6.0 n = 10 -x = sample(n,lb,ub,LowDiscrepancySample(2)) +x = sample(n,lb,ub,HaltonSample()) y = f.(x) scatter(x, y, label="Sampled points", xlims=(lb, ub)) plot!(f, label="True function", xlims=(lb, ub)) diff --git a/docs/src/surrogate.md b/docs/src/surrogate.md index 5af888fda..0260fc781 100644 --- a/docs/src/surrogate.md +++ b/docs/src/surrogate.md @@ -48,7 +48,7 @@ It's great that you want to add another surrogate to the library! You will need to: 1. Define a new mutable struct and a constructor function -2. Define add\_point!(your\_surrogate::AbstactSurrogate,x\_new,y\_new) +2. Define add\_point!(your\_surrogate::AbstractSurrogate,x\_new,y\_new) 3. Define your\_surrogate(value) for the approximation **Example** diff --git a/docs/src/tutorials.md b/docs/src/tutorials.md index 6479b1bb5..eec1fc584 100644 --- a/docs/src/tutorials.md +++ b/docs/src/tutorials.md @@ -43,7 +43,7 @@ using Surrogates f = x -> exp(x)*x^2+x^3 lb = 0.0 ub = 10.0 -x = sample(50,lb,ub,UniformSample()) +x = sample(50,lb,ub,RandomSample()) y = f.(x) p = 1.9 my_krig = Kriging(x,y,lb,ub,p=p) @@ -58,7 +58,7 @@ std_err = std_error_at_point(my_krig,5.4) Let's now optimize the Kriging surrogate using Lower confidence bound method, this is just a one-liner: ```@example kriging -surrogate_optimize(f,LCBS(),lb,ub,my_krig,UniformSample(); maxiters = 10, num_new_samples = 10) +surrogate_optimize(f,LCBS(),lb,ub,my_krig,RandomSample(); maxiters = 10, num_new_samples = 10) ``` Surrogate optimization methods have two purposes: they both sample the space in unknown regions and look for the minima at the same time. diff --git a/lib/SurrogatesAbstractGPs/test/runtests.jl b/lib/SurrogatesAbstractGPs/test/runtests.jl index 28b017eb2..fb553f0e0 100644 --- a/lib/SurrogatesAbstractGPs/test/runtests.jl +++ b/lib/SurrogatesAbstractGPs/test/runtests.jl @@ -27,7 +27,7 @@ using Surrogates: sample, SobolSample x_points = sample(5, lb, ub, SobolSample()) y_points = f.(x_points) agp1D = AbstractGPSurrogate([x_points[1]], [y_points[1]], - gp = GP(SqExponentialKernel()), Σy = 0.05) + gp = GP(SqExponentialKernel()), Σy = 0.05) x_new = 2.5 y_actual = f.(x_new) for i in 2:length(x_points) @@ -87,8 +87,8 @@ using Surrogates: sample, SobolSample a = 2 b = 6 my_k_EI1 = AbstractGPSurrogate(x, y) - surrogate_optimize(objective_function, EI(), a, b, my_k_EI1, UniformSample(), - maxiters = 200, num_new_samples = 155) + surrogate_optimize(objective_function, EI(), a, b, my_k_EI1, RandomSample(), + maxiters = 200, num_new_samples = 155) end @testset "Optimization ND" begin @@ -99,7 +99,7 @@ using Surrogates: sample, SobolSample lb = [1.0, 1.0] ub = [6.0, 6.0] my_k_E1N = AbstractGPSurrogate(x, y) - surrogate_optimize(objective_function_ND, EI(), lb, ub, my_k_E1N, UniformSample()) + surrogate_optimize(objective_function_ND, EI(), lb, ub, my_k_E1N, RandomSample()) end @testset "check working of logpdf_surrogate 1D" begin diff --git a/lib/SurrogatesFlux/src/SurrogatesFlux.jl b/lib/SurrogatesFlux/src/SurrogatesFlux.jl index 6385987b5..f97085fb3 100644 --- a/lib/SurrogatesFlux/src/SurrogatesFlux.jl +++ b/lib/SurrogatesFlux/src/SurrogatesFlux.jl @@ -4,7 +4,6 @@ import Surrogates: add_point!, AbstractSurrogate, _check_dimension export NeuralSurrogate using Flux -using Flux: @epochs mutable struct NeuralSurrogate{X, Y, M, L, O, P, N, A, U} <: AbstractSurrogate x::X @@ -27,12 +26,14 @@ NeuralSurrogate(x,y,lb,ub,model,loss,opt,n_echos) """ function NeuralSurrogate(x, y, lb, ub; model = Chain(Dense(length(x[1]), 1), first), - loss = (x, y) -> Flux.mse(model(x), y), opt = Descent(0.01), - n_echos::Int = 1) + loss = (x, y) -> Flux.mse(model(x), y), opt = Descent(0.01), + n_echos::Int = 1) X = vec.(collect.(x)) data = zip(X, y) ps = Flux.params(model) - @epochs n_echos Flux.train!(loss, ps, data, opt) + for epoch in 1:n_echos + Flux.train!(loss, ps, data, opt) + end return NeuralSurrogate(x, y, model, loss, opt, ps, n_echos, lb, ub) end @@ -58,7 +59,9 @@ function add_point!(my_n::NeuralSurrogate, x_new, y_new) end X = vec.(collect.(my_n.x)) data = zip(X, my_n.y) - @epochs my_n.n_echos Flux.train!(my_n.loss, my_n.ps, data, my_n.opt) + for epoch in 1:(my_n.n_echos) + Flux.train!(my_n.loss, my_n.ps, data, my_n.opt) + end nothing end diff --git a/lib/SurrogatesFlux/test/runtests.jl b/lib/SurrogatesFlux/test/runtests.jl index 5abe83705..eaea94910 100644 --- a/lib/SurrogatesFlux/test/runtests.jl +++ b/lib/SurrogatesFlux/test/runtests.jl @@ -4,7 +4,6 @@ using SafeTestsets using Surrogates using Surrogates: SobolSample using Flux - using Flux: @epochs using SurrogatesFlux using LinearAlgebra using Zygote @@ -20,7 +19,7 @@ using SafeTestsets my_opt = Descent(0.01) n_echos = 1 my_neural = NeuralSurrogate(x, y, a, b, model = my_model, loss = my_loss, opt = my_opt, - n_echos = 1) + n_echos = 1) my_neural_kwargs = NeuralSurrogate(x, y, a, b) add_point!(my_neural, 8.5, 20.0) add_point!(my_neural, [3.2, 3.5], [7.4, 8.0]) @@ -38,7 +37,7 @@ using SafeTestsets my_opt = Descent(0.01) n_echos = 1 my_neural = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) my_neural_kwargs = NeuralSurrogate(x, y, lb, ub) my_neural((3.5, 1.49)) my_neural([3.4, 1.4]) @@ -55,7 +54,7 @@ using SafeTestsets my_model = Chain(Dense(1, 2)) my_loss(x, y) = Flux.mse(my_model(x), y) surrogate = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) surr_kwargs = NeuralSurrogate(x, y, lb, ub) f = x -> [x[1], x[2]^2] @@ -67,7 +66,7 @@ using SafeTestsets my_model = Chain(Dense(2, 2)) my_loss(x, y) = Flux.mse(my_model(x), y) surrogate = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) surrogate_kwargs = NeuralSurrogate(x, y, lb, ub) surrogate((1.0, 2.0)) x_new = (2.0, 2.0) @@ -86,7 +85,7 @@ using SafeTestsets n_echos = 1 my_neural_ND_neural = NeuralSurrogate(x, y, lb, ub) surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_neural_ND_neural, - SobolSample(), maxiters = 15) + SobolSample(), maxiters = 15) # AD Compatibility lb = 0.0 @@ -102,7 +101,7 @@ using SafeTestsets my_opt = Descent(0.01) n_echos = 1 my_neural = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) g = x -> my_neural'(x) g(3.4) end @@ -121,7 +120,7 @@ using SafeTestsets my_opt = Descent(0.01) n_echos = 1 my_neural = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) g = x -> Zygote.gradient(my_neural, x) g((2.0, 5.0)) end @@ -142,7 +141,7 @@ using SafeTestsets my_opt = Descent(0.01) n_echos = 1 my_neural = NeuralSurrogate(x, y, lb, ub, model = my_model, loss = my_loss, - opt = my_opt, n_echos = 1) + opt = my_opt, n_echos = 1) Zygote.gradient(x -> sum(my_neural(x)), (2.0, 5.0)) my_rad = RadialBasis(x, y, lb, ub, rad = linearRadial()) diff --git a/lib/SurrogatesMOE/src/SurrogatesMOE.jl b/lib/SurrogatesMOE/src/SurrogatesMOE.jl index 1833290ab..a2b8df0cc 100644 --- a/lib/SurrogatesMOE/src/SurrogatesMOE.jl +++ b/lib/SurrogatesMOE/src/SurrogatesMOE.jl @@ -1,10 +1,10 @@ module SurrogatesMOE import Surrogates: AbstractSurrogate, linearRadial, cubicRadial, multiquadricRadial, - thinplateRadial, RadialBasisStructure, RadialBasis, - InverseDistanceSurrogate, Kriging, LobachevskyStructure, - LobachevskySurrogate, NeuralStructure, PolyChaosStructure, - LinearSurrogate, add_point! + thinplateRadial, RadialBasisStructure, RadialBasis, + InverseDistanceSurrogate, Kriging, LobachevskyStructure, + LobachevskySurrogate, NeuralStructure, PolyChaosStructure, + LinearSurrogate, add_point! export MOE @@ -46,7 +46,7 @@ function MOE(x, y, expert_types; ndim = 1, n_clusters = 2, quantile = 10) # https://github.com/davidavdav/GaussianMixtures.jl/issues/21 jitter_vals = ((rand(eltype(x_and_y_train), size(x_and_y_train))) ./ 10000) gm_cluster = GMM(n_clusters, x_and_y_train + jitter_vals, kind = :full, nInit = 50, - nIter = 20) + nIter = 20) mvn_distributions = _create_clusters_distributions(gm_cluster, ndim, n_clusters) cluster_classifier_train = _cluster_predict(gm_cluster, x_and_y_train) clusters_train = _cluster_values(x_and_y_train, cluster_classifier_train, n_clusters) @@ -55,7 +55,7 @@ function MOE(x, y, expert_types; ndim = 1, n_clusters = 2, quantile = 10) best_models = [] for i in 1:n_clusters best_model = _find_best_model(clusters_train[i], clusters_test[i], ndim, - expert_types) + expert_types) push!(best_models, best_model) end # X = values[:, 1:ndim] @@ -63,7 +63,7 @@ function MOE(x, y, expert_types; ndim = 1, n_clusters = 2, quantile = 10) #return MOE(X, y, gm_cluster, mvn_distributions, best_models) return MOE(x, y, gm_cluster, mvn_distributions, best_models, expert_types, ndim, - n_clusters) + n_clusters) end """ @@ -224,7 +224,7 @@ finds best model for each set of clustered values by validating against the clus """ function _find_best_model(clustered_train_values, clustered_test_values, dim, - enabled_expert_types) + enabled_expert_types) # find upper and lower bounds for clustered_train and test values concatenated x_vec = [a[1:dim] for a in clustered_train_values] @@ -247,7 +247,7 @@ function _find_best_model(clustered_train_values, clustered_test_values, dim, # call on _surrogate_builder with clustered_train_vals, enabled expert types, lb, ub surr_vec = _surrogate_builder(enabled_expert_types, length(enabled_expert_types), x_vec, - y_vec, lb, ub) + y_vec, lb, ub) # use the models to find best model after validating against test data and return best model best_rmse = Inf @@ -274,9 +274,9 @@ function _surrogate_builder(local_kind, k, x, y, lb, ub) if local_kind[i][1] == "RadialBasis" #fit and append to local_surr my_local_i = RadialBasis(x, y, lb, ub, - rad = local_kind[i].radial_function, - scale_factor = local_kind[i].scale_factor, - sparse = local_kind[i].sparse) + rad = local_kind[i].radial_function, + scale_factor = local_kind[i].scale_factor, + sparse = local_kind[i].sparse) push!(local_surr, my_local_i) elseif local_kind[i][1] == "Kriging" @@ -286,12 +286,12 @@ function _surrogate_builder(local_kind, k, x, y, lb, ub) end my_local_i = Kriging(x, y, lb, ub, p = local_kind[i].p, - theta = local_kind[i].theta) + theta = local_kind[i].theta) push!(local_surr, my_local_i) elseif local_kind[i][1] == "GEK" my_local_i = GEK(x, y, lb, ub, p = local_kind[i].p, - theta = local_kind[i].theta) + theta = local_kind[i].theta) push!(local_surr, my_local_i) elseif local_kind[i] == "LinearSurrogate" @@ -304,21 +304,21 @@ function _surrogate_builder(local_kind, k, x, y, lb, ub) elseif local_kind[i][1] == "LobachevskySurrogate" my_local_i = LobachevskyStructure(x, y, lb, ub, - alpha = local_kind[i].alpha, - n = local_kind[i].n, - sparse = local_kind[i].sparse) + alpha = local_kind[i].alpha, + n = local_kind[i].n, + sparse = local_kind[i].sparse) push!(local_surr, my_local_i) elseif local_kind[i][1] == "NeuralSurrogate" my_local_i = NeuralSurrogate(x, y, lb, ub, - model = local_kind[i].model, - loss = local_kind[i].loss, opt = local_kind[i].opt, - n_echos = local_kind[i].n_echos) + model = local_kind[i].model, + loss = local_kind[i].loss, opt = local_kind[i].opt, + n_echos = local_kind[i].n_echos) push!(local_surr, my_local_i) elseif local_kind[i][1] == "RandomForestSurrogate" my_local_i = RandomForestSurrogate(x, y, lb, ub, - num_round = local_kind[i].num_round) + num_round = local_kind[i].num_round) push!(local_surr, my_local_i) elseif local_kind[i] == "SecondOrderPolynomialSurrogate" @@ -327,7 +327,7 @@ function _surrogate_builder(local_kind, k, x, y, lb, ub) elseif local_kind[i][1] == "Wendland" my_local_i = Wendand(x, y, lb, ub, eps = local_kind[i].eps, - maxiters = local_kind[i].maxiters, tol = local_kind[i].tol) + maxiters = local_kind[i].maxiters, tol = local_kind[i].tol) push!(local_surr, my_local_i) elseif local_kind[i][1] == "PolynomialChaosSurrogate" @@ -363,7 +363,7 @@ function add_point!(m::MOE, x, y) # https://github.com/davidavdav/GaussianMixtures.jl/issues/21 jitter_vals = ((rand(eltype(x_and_y_train), size(x_and_y_train))) ./ 10000) gm_cluster = GMM(m.nc, x_and_y_train + jitter_vals, kind = :full, nInit = 50, - nIter = 20) + nIter = 20) mvn_distributions = _create_clusters_distributions(gm_cluster, m.nd, m.nc) cluster_classifier_train = _cluster_predict(gm_cluster, x_and_y_train) clusters_train = _cluster_values(x_and_y_train, cluster_classifier_train, m.nc) @@ -372,7 +372,7 @@ function add_point!(m::MOE, x, y) best_models = [] for i in 1:(m.nc) best_model = _find_best_model(clusters_train[i], clusters_test[i], m.nd, - m.e) + m.e) push!(best_models, best_model) end m.c = gm_cluster diff --git a/lib/SurrogatesMOE/test/runtests.jl b/lib/SurrogatesMOE/test/runtests.jl index 8344a44b5..f47ea8f63 100644 --- a/lib/SurrogatesMOE/test/runtests.jl +++ b/lib/SurrogatesMOE/test/runtests.jl @@ -23,12 +23,12 @@ Random.seed!(StableRNG(SEED), SEED) # Radials vs MOE RAD_1D = RadialBasis(x, y, lb, ub, rad = linearRadial(), scale_factor = 1.0, - sparse = false) + sparse = false) expert_types = [ RadialBasisStructure(radial_function = linearRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), RadialBasisStructure(radial_function = cubicRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), ] MOE_1D_RAD_RAD = MOE(x, y, expert_types) @@ -78,12 +78,12 @@ end n = 150 x = sample(n, lb, ub, SobolSample()) y = discont_NDIM.(x) - x_test = sample(10, lb, ub, GoldenSample()) + x_test = sample(9, lb, ub, GoldenSample()) expert_types = [ KrigingStructure(p = [1.0, 1.0], theta = [1.0, 1.0]), RadialBasisStructure(radial_function = linearRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), ] moe_nd_krig_rad = MOE(x, y, expert_types, ndim = 2, quantile = 5) moe_pred_vals = moe_nd_krig_rad.(x_test) @@ -116,14 +116,14 @@ end lb = [-1.0, -1.0] ub = [1.0, 1.0] n = 120 - x = sample(n, lb, ub, UniformSample()) + x = sample(n, lb, ub, RandomSample()) y = discont_NDIM.(x) x_test = sample(10, lb, ub, GoldenSample()) # test if MOE handles 3 experts including SurrogatesFlux expert_types = [ RadialBasisStructure(radial_function = linearRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), LinearStructure(), InverseDistanceStructure(p = 1.0), ] @@ -161,9 +161,9 @@ end expert_types = [ RadialBasisStructure(radial_function = linearRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), RadialBasisStructure(radial_function = cubicRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), ] moe = MOE(x, y, expert_types) add_point!(moe, 0.5, 5.0) @@ -184,11 +184,11 @@ end lb = [-1.0, -1.0] ub = [1.0, 1.0] n = 110 - x = sample(n, lb, ub, UniformSample()) + x = sample(n, lb, ub, RandomSample()) y = discont_NDIM.(x) expert_types = [InverseDistanceStructure(p = 1.0), RadialBasisStructure(radial_function = linearRadial(), scale_factor = 1.0, - sparse = false), + sparse = false), ] moe_nd_inv_rad = MOE(x, y, expert_types, ndim = 2) add_point!(moe_nd_inv_rad, (0.5, 0.5), sum((0.5, 0.5) .^ 2) + 5) diff --git a/lib/SurrogatesPolyChaos/src/SurrogatesPolyChaos.jl b/lib/SurrogatesPolyChaos/src/SurrogatesPolyChaos.jl index 634b885f9..27f962dd6 100644 --- a/lib/SurrogatesPolyChaos/src/SurrogatesPolyChaos.jl +++ b/lib/SurrogatesPolyChaos/src/SurrogatesPolyChaos.jl @@ -25,7 +25,7 @@ function _calculatepce_coeff(x, y, num_of_multi_indexes, op::AbstractCanonicalOr end function PolynomialChaosSurrogate(x, y, lb::Number, ub::Number; - op::AbstractCanonicalOrthoPoly = GaussOrthoPoly(2)) + op::AbstractCanonicalOrthoPoly = GaussOrthoPoly(2)) n = length(x) poly_degree = op.deg num_of_multi_indexes = 1 + poly_degree @@ -59,9 +59,9 @@ function _calculatepce_coeff(x, y, num_of_multi_indexes, op::MultiOrthoPoly) end function PolynomialChaosSurrogate(x, y, lb, ub; - op::MultiOrthoPoly = MultiOrthoPoly([GaussOrthoPoly(2) - for j in 1:length(lb)], - 2)) + op::MultiOrthoPoly = MultiOrthoPoly([GaussOrthoPoly(2) + for j in 1:length(lb)], + 2)) n = length(x) d = length(lb) poly_degree = op.deg @@ -82,7 +82,7 @@ function (pcND::PolynomialChaosSurrogate)(val) sum = sum + pcND.coeff[i] * first(PolyChaos.evaluate(pcND.ortopolys.ind[i, :], collect(val), - pcND.ortopolys)) + pcND.ortopolys)) end return sum end @@ -93,12 +93,12 @@ function add_point!(polych::PolynomialChaosSurrogate, x_new, y_new) polych.x = vcat(polych.x, x_new) polych.y = vcat(polych.y, y_new) polych.coeff = _calculatepce_coeff(polych.x, polych.y, polych.num_of_multi_indexes, - polych.ortopolys) + polych.ortopolys) else polych.x = vcat(polych.x, x_new) polych.y = vcat(polych.y, y_new) polych.coeff = _calculatepce_coeff(polych.x, polych.y, polych.num_of_multi_indexes, - polych.ortopolys) + polych.ortopolys) end nothing end diff --git a/lib/SurrogatesPolyChaos/test/runtests.jl b/lib/SurrogatesPolyChaos/test/runtests.jl index 9d913d960..767b4b19e 100644 --- a/lib/SurrogatesPolyChaos/test/runtests.jl +++ b/lib/SurrogatesPolyChaos/test/runtests.jl @@ -49,12 +49,12 @@ using SafeTestsets y = objective_function.(x) my_poly1d = PolynomialChaosSurrogate(x, y, lb, ub) @test_broken surrogate_optimize(objective_function, SRBF(), a, b, my_poly1d, - LowDiscrepancySample(; base = 2)) + LowDiscrepancySample(; base = 2)) lb = [0.0, 0.0] ub = [10.0, 10.0] obj_ND = x -> log(x[1]) * exp(x[2]) - x = sample(40, lb, ub, UniformSample()) + x = sample(40, lb, ub, RandomSample()) y = obj_ND.(x) my_polyND = PolynomialChaosSurrogate(x, y, lb, ub) surrogate_optimize(obj_ND, SRBF(), lb, ub, my_polyND, SobolSample(), maxiters = 15) diff --git a/lib/SurrogatesRandomForest/src/SurrogatesRandomForest.jl b/lib/SurrogatesRandomForest/src/SurrogatesRandomForest.jl index 69532f999..b3db175d4 100644 --- a/lib/SurrogatesRandomForest/src/SurrogatesRandomForest.jl +++ b/lib/SurrogatesRandomForest/src/SurrogatesRandomForest.jl @@ -50,7 +50,8 @@ function add_point!(rndfor::RandomForestSurrogate, x_new, y_new) #1D rndfor.x = vcat(rndfor.x, x_new) rndfor.y = vcat(rndfor.y, y_new) - rndfor.bst = xgboost((reshape(rndfor.x, length(rndfor.x), 1), rndfor.y); num_round = rndfor.num_round) + rndfor.bst = xgboost((reshape(rndfor.x, length(rndfor.x), 1), rndfor.y); + num_round = rndfor.num_round) else n_previous = length(rndfor.x) a = vcat(rndfor.x, x_new) diff --git a/lib/SurrogatesSVM/src/SurrogatesSVM.jl b/lib/SurrogatesSVM/src/SurrogatesSVM.jl index 65da3087f..6cc23f388 100644 --- a/lib/SurrogatesSVM/src/SurrogatesSVM.jl +++ b/lib/SurrogatesSVM/src/SurrogatesSVM.jl @@ -48,7 +48,7 @@ function add_point!(svmsurr::SVMSurrogate, x_new, y_new) svmsurr.x = vcat(svmsurr.x, x_new) svmsurr.y = vcat(svmsurr.y, y_new) svmsurr.model = LIBSVM.fit!(SVC(), reshape(svmsurr.x, length(svmsurr.x), 1), - svmsurr.y) + svmsurr.y) else n_previous = length(svmsurr.x) a = vcat(svmsurr.x, x_new) diff --git a/lib/SurrogatesSVM/test/runtests.jl b/lib/SurrogatesSVM/test/runtests.jl index b3b0eec08..5919c8f29 100644 --- a/lib/SurrogatesSVM/test/runtests.jl +++ b/lib/SurrogatesSVM/test/runtests.jl @@ -20,7 +20,7 @@ using SafeTestsets obj_N = x -> x[1]^2 * x[2] lb = [0.0, 0.0] ub = [10.0, 10.0] - x = sample(100, lb, ub, UniformSample()) + x = sample(100, lb, ub, RandomSample()) y = obj_N.(x) my_svm_ND = SVMSurrogate(x, y, lb, ub) val = my_svm_ND((5.0, 1.2)) diff --git a/src/Earth.jl b/src/Earth.jl index 0a4d79490..fb620b745 100644 --- a/src/Earth.jl +++ b/src/Earth.jl @@ -149,15 +149,15 @@ function _backward_pass_1d(x, y, n_min_terms, basis, penalty, rel_GCV) end function EarthSurrogate(x, y, lb::Number, ub::Number; penalty::Number = 2.0, - n_min_terms::Int = 2, n_max_terms::Int = 10, - rel_res_error::Number = 1e-2, rel_GCV::Number = 1e-2, - maxiters = 100) + n_min_terms::Int = 2, n_max_terms::Int = 10, + rel_res_error::Number = 1e-2, rel_GCV::Number = 1e-2, + maxiters = 100) intercept = sum([y[i] for i in 1:length(y)]) / length(y) basis_after_forward = _forward_pass_1d(x, y, n_max_terms, rel_res_error, maxiters) basis = _backward_pass_1d(x, y, n_min_terms, basis_after_forward, penalty, rel_GCV) coeff = _coeff_1d(x, y, basis) return EarthSurrogate(x, y, lb, ub, basis, coeff, penalty, n_min_terms, n_max_terms, - rel_res_error, rel_GCV, intercept, maxiters) + rel_res_error, rel_GCV, intercept, maxiters) end function (earth::EarthSurrogate)(val::Number) @@ -319,14 +319,14 @@ function _backward_pass_nd(x, y, n_min_terms, basis, penalty, rel_GCV) end function EarthSurrogate(x, y, lb, ub; penalty::Number = 2.0, n_min_terms::Int = 2, - n_max_terms::Int = 10, rel_res_error::Number = 1e-2, - rel_GCV::Number = 1e-2, maxiters = 100) + n_max_terms::Int = 10, rel_res_error::Number = 1e-2, + rel_GCV::Number = 1e-2, maxiters = 100) intercept = sum([y[i] for i in 1:length(y)]) / length(y) basis_after_forward = _forward_pass_nd(x, y, n_max_terms, rel_res_error, maxiters) basis = _backward_pass_nd(x, y, n_min_terms, basis_after_forward, penalty, rel_GCV) coeff = _coeff_nd(x, y, basis) return EarthSurrogate(x, y, lb, ub, basis, coeff, penalty, n_min_terms, n_max_terms, - rel_res_error, rel_GCV, intercept, maxiters) + rel_res_error, rel_GCV, intercept, maxiters) end function (earth::EarthSurrogate)(val) @@ -343,9 +343,9 @@ function add_point!(earth::EarthSurrogate, x_new, y_new) earth.y = vcat(earth.y, y_new) earth.intercept = sum([earth.y[i] for i in 1:length(earth.y)]) / length(earth.y) basis_after_forward = _forward_pass_1d(earth.x, earth.y, earth.n_max_terms, - earth.rel_res_error, earth.maxiters) + earth.rel_res_error, earth.maxiters) earth.basis = _backward_pass_1d(earth.x, earth.y, earth.n_min_terms, - basis_after_forward, earth.penalty, earth.rel_GCV) + basis_after_forward, earth.penalty, earth.rel_GCV) earth.coeff = _coeff_1d(earth.x, earth.y, earth.basis) nothing else @@ -354,9 +354,9 @@ function add_point!(earth::EarthSurrogate, x_new, y_new) earth.y = vcat(earth.y, y_new) earth.intercept = sum([earth.y[i] for i in 1:length(earth.y)]) / length(earth.y) basis_after_forward = _forward_pass_nd(earth.x, earth.y, earth.n_max_terms, - earth.rel_res_error, earth.maxiters) + earth.rel_res_error, earth.maxiters) earth.basis = _backward_pass_nd(earth.x, earth.y, earth.n_min_terms, - basis_after_forward, earth.penalty, earth.rel_GCV) + basis_after_forward, earth.penalty, earth.rel_GCV) earth.coeff = _coeff_nd(earth.x, earth.y, earth.basis) nothing end diff --git a/src/GEK.jl b/src/GEK.jl index d3f1f7042..75da4ca3b 100644 --- a/src/GEK.jl +++ b/src/GEK.jl @@ -93,7 +93,7 @@ end function GEK(x, y, lb::Number, ub::Number; p = 1.0, theta = 1.0) if length(x) != length(unique(x)) - println("There exists a repetion in the samples, cannot build Kriging.") + println("There exists a repetition in the samples, cannot build Kriging.") return end mu, b, sigma, inverse_of_R = _calc_gek_coeffs(x, y, p, theta) diff --git a/src/GEKPLS.jl b/src/GEKPLS.jl index 33dc2242f..1e26bf26f 100644 --- a/src/GEKPLS.jl +++ b/src/GEKPLS.jl @@ -72,21 +72,21 @@ function GEKPLS(x_vec, y_vec, grads_vec, n_comp, delta_x, lb, ub, extra_points, end pls_mean, X_after_PLS, y_after_PLS = _ge_compute_pls(X, y, n_comp, grads, delta_x, - xlimits, extra_points) + xlimits, extra_points) X_after_std, y_after_std, X_offset, y_mean, X_scale, y_std = standardization(X_after_PLS, - y_after_PLS) + y_after_PLS) D, ij = cross_distances(X_after_std) pls_mean_reshaped = reshape(pls_mean, (size(X, 2), n_comp)) d = componentwise_distance_PLS(D, "squar_exp", n_comp, pls_mean_reshaped) nt, nd = size(X_after_PLS) beta, gamma, reduced_likelihood_function_value = _reduced_likelihood_function(theta, - "squar_exp", - d, nt, ij, - y_after_std) + "squar_exp", + d, nt, ij, + y_after_std) return GEKPLS(x_vec, y_vec, X, y, grads, xlimits, delta_x, extra_points, n_comp, beta, - gamma, theta, - reduced_likelihood_function_value, - X_offset, X_scale, X_after_std, pls_mean_reshaped, y_mean, y_std) + gamma, theta, + reduced_likelihood_function_value, + X_offset, X_scale, X_after_std, pls_mean_reshaped, y_mean, y_std) end """ @@ -134,21 +134,21 @@ function add_point!(g::GEKPLS, x_tup, y_val, grad_tup) g.y_matrix = vcat(g.y_matrix, y_val) g.grads = vcat(g.grads, new_grads) pls_mean, X_after_PLS, y_after_PLS = _ge_compute_pls(g.x_matrix, g.y_matrix, - g.num_components, - g.grads, g.delta, g.xl, - g.extra_points) + g.num_components, + g.grads, g.delta, g.xl, + g.extra_points) g.X_after_std, y_after_std, g.X_offset, g.y_mean, g.X_scale, g.y_std = standardization(X_after_PLS, - y_after_PLS) + y_after_PLS) D, ij = cross_distances(g.X_after_std) g.pls_mean = reshape(pls_mean, (size(g.x_matrix, 2), g.num_components)) d = componentwise_distance_PLS(D, "squar_exp", g.num_components, g.pls_mean) nt, nd = size(X_after_PLS) g.beta, g.gamma, g.reduced_likelihood_function_value = _reduced_likelihood_function(g.theta, - "squar_exp", - d, - nt, - ij, - y_after_std) + "squar_exp", + d, + nt, + ij, + y_after_std) end """ @@ -185,14 +185,14 @@ function _ge_compute_pls(X, y, n_comp, grads, delta_x, xlimits, extra_points) bb_vals = circshift(boxbehnken(dim, 1), 1) else bb_vals = [0.0 0.0; #center - 1.0 0.0; #right - 0.0 1.0; #up - -1.0 0.0; #left - 0.0 -1.0; #down - 1.0 1.0; #right up - -1.0 1.0; #left up - -1.0 -1.0; #left down - 1.0 -1.0] + 1.0 0.0; #right + 0.0 1.0; #up + -1.0 0.0; #left + 0.0 -1.0; #down + 1.0 1.0; #right up + -1.0 1.0; #left up + -1.0 -1.0; #left down + 1.0 -1.0] end _X = zeros((size(bb_vals)[1], dim)) _y = zeros((size(bb_vals)[1], 1)) @@ -201,8 +201,8 @@ function _ge_compute_pls(X, y, n_comp, grads, delta_x, xlimits, extra_points) bb_vals = bb_vals .* grads[i, :]' _y = y[i, :] .+ sum(bb_vals, dims = 2) - #_pls.fit(_X, _y) # relic from sklearn versiom; retained for future reference. - #coeff_pls[:, :, i] = _pls.x_rotations_ #relic from sklearn versiom; retained for future reference. + #_pls.fit(_X, _y) # relic from sklearn version; retained for future reference. + #coeff_pls[:, :, i] = _pls.x_rotations_ #relic from sklearn version; retained for future reference. coeff_pls[:, :, i] = _modified_pls(_X, _y, n_comp) #_modified_pls returns the equivalent of SKLearn's _pls.x_rotations_ if extra_points != 0 @@ -273,9 +273,9 @@ function boxbehnken(matrix_size::Int, center::Int) for j in (i + 1):matrix_size l = l + 1 A[(max(0, (l - 1) * size(A_fact)[1]) + 1):(l * size(A_fact)[1]), i] = A_fact[:, - 1] + 1] A[(max(0, (l - 1) * size(A_fact)[1]) + 1):(l * size(A_fact)[1]), j] = A_fact[:, - 2] + 2] end end @@ -304,7 +304,7 @@ end ######end of bb design###### """ -We substract the mean from each variable. Then, we divide the values of each +We subtract the mean from each variable. Then, we divide the values of each variable by its standard deviation. Parameters diff --git a/src/Kriging.jl b/src/Kriging.jl index e0b3a3671..f48306069 100644 --- a/src/Kriging.jl +++ b/src/Kriging.jl @@ -46,12 +46,12 @@ function std_error_at_point(k::Kriging, val) d = length(k.x[1]) r = zeros(eltype(k.x[1]), n, 1) r = [let - sum = zero(eltype(k.x[1])) - for l in 1:d - sum = sum + k.theta[l] * norm(val[l] - k.x[i][l])^(k.p[l]) - end - exp(-sum) - end + sum = zero(eltype(k.x[1])) + for l in 1:d + sum = sum + k.theta[l] * norm(val[l] - k.x[i][l])^(k.p[l]) + end + exp(-sum) + end for i in 1:n] one = ones(eltype(k.x[1]), n, 1) @@ -102,9 +102,9 @@ Constructor for type Kriging. - theta: value > 0 modeling how much the function is changing in the i-th variable. """ function Kriging(x, y, lb::Number, ub::Number; p = 2.0, - theta = 0.5 / max(1e-6 * abs(ub - lb), std(x))^p) + theta = 0.5 / max(1e-6 * abs(ub - lb), std(x))^p) if length(x) != length(unique(x)) - println("There exists a repetion in the samples, cannot build Kriging.") + println("There exists a repetition in the samples, cannot build Kriging.") return end @@ -168,8 +168,8 @@ Constructor for Kriging surrogate. changing in the i-th variable. """ function Kriging(x, y, lb, ub; p = 2.0 .* collect(one.(x[1])), - theta = [0.5 / max(1e-6 * norm(ub .- lb), std(x_i[i] for x_i in x))^p[i] - for i in 1:length(x[1])]) + theta = [0.5 / max(1e-6 * norm(ub .- lb), std(x_i[i] for x_i in x))^p[i] + for i in 1:length(x[1])]) if length(x) != length(unique(x)) println("There exists a repetition in the samples, cannot build Kriging.") return @@ -194,12 +194,12 @@ function _calc_kriging_coeffs(x, y, p, theta) d = length(x[1]) R = [let - sum = zero(eltype(x[1])) - for l in 1:d - sum = sum + theta[l] * norm(x[i][l] - x[j][l])^p[l] - end - exp(-sum) - end + sum = zero(eltype(x[1])) + for l in 1:d + sum = sum + theta[l] * norm(x[i][l] - x[j][l])^p[l] + end + exp(-sum) + end for j in 1:n, i in 1:n] # Estimate nugget based on maximum allowed condition number diff --git a/src/Lobachevsky.jl b/src/Lobachevsky.jl index 52fb0a123..30c890afb 100644 --- a/src/Lobachevsky.jl +++ b/src/Lobachevsky.jl @@ -45,7 +45,7 @@ end Lobachevsky interpolation, suggested parameters: 0 <= alpha <= 4, n must be even. """ function LobachevskySurrogate(x, y, lb::Number, ub::Number; alpha::Number = 1.0, n::Int = 4, - sparse = false) + sparse = false) if alpha > 4 || alpha < 0 error("Alpha must be between 0 and 4") end @@ -89,7 +89,7 @@ LobachevskySurrogate(x,y,alpha,n::Int,lb,ub,sparse = false) Build the Lobachevsky surrogate with parameters alpha and n. """ function LobachevskySurrogate(x, y, lb, ub; alpha = collect(one.(x[1])), n::Int = 4, - sparse = false) + sparse = false) if n % 2 != 0 error("Parameter n must be even") end @@ -199,5 +199,5 @@ function lobachevsky_integrate_dimension(loba::LobachevskySurrogate, lb, ub, dim new_ub = deleteat!(ub, dim) new_loba = deleteat!(loba.alpha, dim) return LobachevskySurrogate(new_x, loba.y, loba.alpha, loba.n, new_lb, new_ub, - new_coeff, loba.sparse) + new_coeff, loba.sparse) end diff --git a/src/Optimization.jl b/src/Optimization.jl index 81e8e3523..cc615a983 100755 --- a/src/Optimization.jl +++ b/src/Optimization.jl @@ -32,7 +32,7 @@ struct RTEA{K, Z, P, N, S} <: SurrogateOptimizationAlgorithm end function merit_function(point, w, surr::AbstractSurrogate, s_max, s_min, d_max, d_min, - box_size) + box_size) if length(point) == 1 D_x = box_size + 1 for i in 1:length(surr.x) @@ -84,8 +84,8 @@ a few values to achieve both exploitation and exploration. When w is close to zero, we do pure exploration, while w close to 1 corresponds to exploitation. """ function surrogate_optimize(obj::Function, ::SRBF, lb, ub, surr::AbstractSurrogate, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100, needs_gradient = false) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100, needs_gradient = false) scale = 0.2 success = 0 failure = 0 @@ -110,18 +110,8 @@ function surrogate_optimize(obj::Function, ::SRBF, lb, ub, surr::AbstractSurroga new_lb = incumbent_x .- 3 * scale * norm(incumbent_x .- lb) new_ub = incumbent_x .+ 3 * scale * norm(incumbent_x .- ub) - - @inbounds for i in 1:length(new_lb) - if new_lb[i] < lb[i] - new_lb = collect(new_lb) - new_lb[i] = lb[i] - end - if new_ub[i] > ub[i] - new_ub = collect(new_ub) - new_ub[i] = ub[i] - end - end - + new_lb = vec(max.(new_lb, lb)) + new_ub = vec(min.(new_ub, ub)) new_sample = sample(num_new_samples, new_lb, new_ub, sample_type) s = zeros(eltype(surr.x[1]), num_new_samples) for j in 1:num_new_samples @@ -149,8 +139,8 @@ function surrogate_optimize(obj::Function, ::SRBF, lb, ub, surr::AbstractSurroga evaluation_of_merit_function = zeros(float(eltype(surr.x[1])), num_new_samples) @inbounds for r in 1:num_new_samples evaluation_of_merit_function[r] = merit_function(new_sample[r], w, surr, - s_max, s_min, d_max, d_min, - box_size) + s_max, s_min, d_max, d_min, + box_size) end new_addition = false adaptive_point_x = Tuple{} @@ -245,8 +235,8 @@ SRBF 1D: surrogate_optimize(obj::Function,::SRBF,lb::Number,ub::Number,surr::AbstractSurrogate,sample_type::SamplingAlgorithm;maxiters=100,num_new_samples=100) """ function surrogate_optimize(obj::Function, ::SRBF, lb::Number, ub::Number, - surr::AbstractSurrogate, sample_type::SamplingAlgorithm; - maxiters = 100, num_new_samples = 100) + surr::AbstractSurrogate, sample_type::SamplingAlgorithm; + maxiters = 100, num_new_samples = 100) #Suggested by: #https://www.mathworks.com/help/gads/surrogate-optimization-algorithm.html scale = 0.2 @@ -302,7 +292,7 @@ function surrogate_optimize(obj::Function, ::SRBF, lb::Number, ub::Number, end #3) Evaluate merit function at the sampled points evaluation_of_merit_function = merit_function.(new_sample, w, surr, s_max, - s_min, d_max, d_min, box_size) + s_min, d_max, d_min, box_size) new_addition = false adaptive_point_x = zero(eltype(new_sample[1])) @@ -384,9 +374,9 @@ function surrogate_optimize(obj::Function, ::SRBF, lb::Number, ub::Number, end # Ask SRBF ND -function potential_optimal_points(::SRBF, strategy, lb, ub, surr::AbstractSurrogate, sample_type::SamplingAlgorithm, n_parallel; - num_new_samples = 500) - +function potential_optimal_points(::SRBF, strategy, lb, ub, surr::AbstractSurrogate, + sample_type::SamplingAlgorithm, n_parallel; + num_new_samples = 500) scale = 0.2 w_range = [0.3, 0.5, 0.7, 0.95] w_cycle = Iterators.cycle(w_range) @@ -437,7 +427,6 @@ function potential_optimal_points(::SRBF, strategy, lb, ub, surr::AbstractSurrog tmp_surr = deepcopy(surr) - new_addition = 0 diff_x = zeros(eltype(surr.x[1]), d) @@ -491,9 +480,10 @@ function potential_optimal_points(::SRBF, strategy, lb, ub, surr::AbstractSurrog end # Ask SRBF 1D -function potential_optimal_points(::SRBF, strategy, lb::Number, ub::Number, surr::AbstractSurrogate, - sample_type::SamplingAlgorithm, n_parallel; - num_new_samples = 500) +function potential_optimal_points(::SRBF, strategy, lb::Number, ub::Number, + surr::AbstractSurrogate, + sample_type::SamplingAlgorithm, n_parallel; + num_new_samples = 500) scale = 0.2 success = 0 w_range = [0.3, 0.5, 0.7, 0.95] @@ -590,7 +580,6 @@ function potential_optimal_points(::SRBF, strategy, lb::Number, ub::Number, surr return (proposed_points_x, merit_of_proposed_points) end - """ This is an implementation of Lower Confidence Bound (LCB), a popular acquisition function in Bayesian optimization. @@ -599,8 +588,8 @@ Under a Gaussian process (GP) prior, the goal is to minimize: default value ``k = 2``. """ function surrogate_optimize(obj::Function, ::LCBS, lb::Number, ub::Number, krig, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100, k = 2.0) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100, k = 2.0) dtol = 1e-3 * norm(ub - lb) for i in 1:maxiters new_sample = sample(num_new_samples, lb, ub, sample_type) @@ -660,8 +649,8 @@ Under a Gaussian process (GP) prior, the goal is to minimize: default value ``k = 2``. """ function surrogate_optimize(obj::Function, ::LCBS, lb, ub, krig, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100, k = 2.0) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100, k = 2.0) dtol = 1e-3 * norm(ub - lb) for i in 1:maxiters d = length(krig.x) @@ -720,8 +709,8 @@ end Expected improvement method 1D """ function surrogate_optimize(obj::Function, ::EI, lb::Number, ub::Number, krig, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100) dtol = 1e-3 * norm(ub - lb) eps = 0.01 for i in 1:maxiters @@ -786,9 +775,9 @@ function surrogate_optimize(obj::Function, ::EI, lb::Number, ub::Number, krig, end # Ask EI 1D & ND -function potential_optimal_points(::EI, strategy, lb, ub, krig, sample_type::SamplingAlgorithm, n_parallel::Number; - num_new_samples = 100) - +function potential_optimal_points(::EI, strategy, lb, ub, krig, + sample_type::SamplingAlgorithm, n_parallel::Number; + num_new_samples = 100) lb = krig.lb ub = krig.ub @@ -863,8 +852,8 @@ maximize expected improvement: """ function surrogate_optimize(obj::Function, ::EI, lb, ub, krig, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100) dtol = 1e-3 * norm(ub - lb) eps = 0.01 for i in 1:maxiters @@ -945,7 +934,7 @@ function adjust_step_size(sigma_n, sigma_min, C_success, t_success, C_fail, t_fa end function select_evaluation_point_1D(new_points1, surr1::AbstractSurrogate, numb_iters, - maxiters) + maxiters) v = [0.3, 0.5, 0.8, 0.95] k = 4 n = length(surr1.x) @@ -1006,8 +995,8 @@ surrogates and dynamic coordinate search in high-dimensional expensive black-box """ function surrogate_optimize(obj::Function, ::DYCORS, lb::Number, ub::Number, - surr1::AbstractSurrogate, sample_type::SamplingAlgorithm; - maxiters = 100, num_new_samples = 100) + surr1::AbstractSurrogate, sample_type::SamplingAlgorithm; + maxiters = 100, num_new_samples = 100) x_best = argmin(surr1.y) y_best = minimum(surr1.y) sigma_n = 0.2 * norm(ub - lb) @@ -1029,14 +1018,14 @@ function surrogate_optimize(obj::Function, ::DYCORS, lb::Number, ub::Number, if new_points[i] > ub #reflection new_points[i] = max(lb, - maximum(surr1.x) - - norm(new_points[i] - maximum(surr1.x))) + maximum(surr1.x) - + norm(new_points[i] - maximum(surr1.x))) end if new_points[i] < lb #reflection new_points[i] = min(ub, - minimum(surr1.x) + - norm(new_points[i] - minimum(surr1.x))) + minimum(surr1.x) + + norm(new_points[i] - minimum(surr1.x))) end end end @@ -1053,7 +1042,7 @@ function surrogate_optimize(obj::Function, ::DYCORS, lb::Number, ub::Number, end sigma_n, C_success, C_fail = adjust_step_size(sigma_n, sigma_min, C_success, - t_success, C_fail, t_fail) + t_success, C_fail, t_fail) if f_new < y_best x_best = x_new @@ -1066,7 +1055,7 @@ function surrogate_optimize(obj::Function, ::DYCORS, lb::Number, ub::Number, end function select_evaluation_point_ND(new_points, surrn::AbstractSurrogate, numb_iters, - maxiters) + maxiters) v = [0.3, 0.5, 0.8, 0.95] k = 4 n = size(surrn.x, 1) @@ -1134,8 +1123,8 @@ to perturb a given coordinate and decrease this probability after each function evaluation so fewer coordinates are perturbed later in the optimization. """ function surrogate_optimize(obj::Function, ::DYCORS, lb, ub, surrn::AbstractSurrogate, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = 100) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = 100) x_best = collect(surrn.x[argmin(surrn.y)]) y_best = minimum(surrn.y) sigma_n = 0.2 * norm(ub - lb) @@ -1170,13 +1159,13 @@ function surrogate_optimize(obj::Function, ::DYCORS, lb, ub, surrn::AbstractSurr while new_points[i, j] < lb[j] || new_points[i, j] > ub[j] if new_points[i, j] > ub[j] new_points[i, j] = max(lb[j], - maximum(surrn.x)[j] - - norm(new_points[i, j] - maximum(surrn.x)[j])) + maximum(surrn.x)[j] - + norm(new_points[i, j] - maximum(surrn.x)[j])) end if new_points[i, j] < lb[j] new_points[i, j] = min(ub[j], - minimum(surrn.x)[j] + - norm(new_points[i] - minimum(surrn.x)[j])) + minimum(surrn.x)[j] + + norm(new_points[i] - minimum(surrn.x)[j])) end end end @@ -1195,7 +1184,7 @@ function surrogate_optimize(obj::Function, ::DYCORS, lb, ub, surrn::AbstractSurr end sigma_n, C_success, C_fail = adjust_step_size(sigma_n, sigma_min, C_success, - t_success, C_fail, t_fail) + t_success, C_fail, t_fail) if f_new < y_best x_best = x_new @@ -1321,8 +1310,8 @@ SOP Surrogate optimization method, following closely the following papers: #Suggested number of new_samples = min(500*d,5000) """ function surrogate_optimize(obj::Function, sop1::SOP, lb::Number, ub::Number, - surrSOP::AbstractSurrogate, sample_type::SamplingAlgorithm; - maxiters = 100, num_new_samples = min(500 * 1, 5000)) + surrSOP::AbstractSurrogate, sample_type::SamplingAlgorithm; + maxiters = 100, num_new_samples = min(500 * 1, 5000)) d = length(lb) N_fail = 3 N_tenure = 5 @@ -1568,8 +1557,8 @@ function II_tier_ranking_ND(D::Dict, srgD::AbstractSurrogate) end function surrogate_optimize(obj::Function, sopd::SOP, lb, ub, surrSOPD::AbstractSurrogate, - sample_type::SamplingAlgorithm; maxiters = 100, - num_new_samples = min(500 * length(lb), 5000)) + sample_type::SamplingAlgorithm; maxiters = 100, + num_new_samples = min(500 * length(lb), 5000)) d = length(lb) N_fail = 3 N_tenure = 5 @@ -1701,7 +1690,7 @@ function surrogate_optimize(obj::Function, sopd::SOP, lb, ub, surrSOPD::Abstract new_points_y[i] = y_best end - #new_points[i] is splitted in new_points_x and new_points_y now contains: + #new_points[i] is split in new_points_x and new_points_y now contains: #[x_1,y_1; x_2,y_2,...,x_{num_new_samples},y_{num_new_samples}] #2.4 Adaptive learning and tabu archive @@ -1751,7 +1740,7 @@ function _nonDominatedSorting(arr::Array{Float64, 2}) while !isempty(arr) s = size(arr, 1) red = dropdims(sum([_dominates(arr[i, :], arr[j, :]) for i in 1:s, j in 1:s], - dims = 1) .== 0, dims = 1) + dims = 1) .== 0, dims = 1) a = 1:s sel::Array{Int64, 1} = a[red] push!(fronts, ind[sel]) @@ -1763,8 +1752,8 @@ function _nonDominatedSorting(arr::Array{Float64, 2}) end function surrogate_optimize(obj::Function, sbm::SMB, lb::Number, ub::Number, - surrSMB::AbstractSurrogate, sample_type::SamplingAlgorithm; - maxiters = 100, n_new_look = 1000) + surrSMB::AbstractSurrogate, sample_type::SamplingAlgorithm; + maxiters = 100, n_new_look = 1000) #obj contains a function for each output dimension dim_out = length(surrSMB.y[1]) d = 1 @@ -1803,8 +1792,8 @@ function surrogate_optimize(obj::Function, sbm::SMB, lb::Number, ub::Number, end function surrogate_optimize(obj::Function, smb::SMB, lb, ub, surrSMBND::AbstractSurrogate, - sample_type::SamplingAlgorithm; maxiters = 100, - n_new_look = 1000) + sample_type::SamplingAlgorithm; maxiters = 100, + n_new_look = 1000) #obj contains a function for each output dimension dim_out = length(surrSMBND.y[1]) d = length(lb) @@ -1844,8 +1833,8 @@ end # RTEA (Noisy model based multi objective optimization + standard rtea by fieldsen), use this for very noisy objective functions because there are a lot of re-evaluations function surrogate_optimize(obj, rtea::RTEA, lb::Number, ub::Number, - surrRTEA::AbstractSurrogate, sample_type::SamplingAlgorithm; - maxiters = 100, n_new_look = 1000) + surrRTEA::AbstractSurrogate, sample_type::SamplingAlgorithm; + maxiters = 100, n_new_look = 1000) Z = rtea.z K = rtea.k p_cross = rtea.p @@ -1950,8 +1939,8 @@ function surrogate_optimize(obj, rtea::RTEA, lb::Number, ub::Number, end function surrogate_optimize(obj, rtea::RTEA, lb, ub, surrRTEAND::AbstractSurrogate, - sample_type::SamplingAlgorithm; maxiters = 100, - n_new_look = 1000) + sample_type::SamplingAlgorithm; maxiters = 100, + n_new_look = 1000) Z = rtea.z K = rtea.k p_cross = rtea.p @@ -2057,7 +2046,7 @@ function surrogate_optimize(obj, rtea::RTEA, lb, ub, surrRTEAND::AbstractSurroga end function surrogate_optimize(obj::Function, ::EI, lb, ub, krig, sample_type::SectionSample; - maxiters = 100, num_new_samples = 100) + maxiters = 100, num_new_samples = 100) dtol = 1e-3 * norm(ub - lb) eps = 0.01 for i in 1:maxiters @@ -2105,7 +2094,7 @@ function surrogate_optimize(obj::Function, ::EI, lb, ub, krig, sample_type::Sect if length(new_sample) == 0 println("Out of sampling points.") return section_sampler_returner(sample_type, krig.x, krig.y, lb, ub, - krig) + krig) end else point_found = true @@ -2125,12 +2114,12 @@ function surrogate_optimize(obj::Function, ::EI, lb, ub, krig, sample_type::Sect end function section_sampler_returner(sample_type::SectionSample, surrn_x, surrn_y, - lb, ub, surrn) - d_fixed = QuasiMonteCarlo.fixed_dimensions(sample_type) + lb, ub, surrn) + d_fixed = fixed_dimensions(sample_type) @assert length(surrn_y) == size(surrn_x)[1] surrn_xy = [(surrn_x[y], surrn_y[y]) for y in 1:length(surrn_y)] section_surr1_xy = filter(xyz -> xyz[1][d_fixed] == Tuple(sample_type.x0[d_fixed]), - surrn_xy) + surrn_xy) section_surr1_x = [xy[1] for xy in section_surr1_xy] section_surr1_y = [xy[2] for xy in section_surr1_xy] if length(section_surr1_xy) == 0 diff --git a/src/PolynomialChaos.jl b/src/PolynomialChaos.jl index 76e89e1df..81e72600b 100644 --- a/src/PolynomialChaos.jl +++ b/src/PolynomialChaos.jl @@ -20,7 +20,7 @@ function _calculatepce_coeff(x, y, num_of_multi_indexes, op::AbstractCanonicalOr end function PolynomialChaosSurrogate(x, y, lb::Number, ub::Number; - op::AbstractCanonicalOrthoPoly = GaussOrthoPoly(2)) + op::AbstractCanonicalOrthoPoly = GaussOrthoPoly(2)) n = length(x) poly_degree = op.deg num_of_multi_indexes = 1 + poly_degree @@ -53,9 +53,9 @@ function _calculatepce_coeff(x, y, num_of_multi_indexes, op::MultiOrthoPoly) end function PolynomialChaosSurrogate(x, y, lb, ub; - op::MultiOrthoPoly = MultiOrthoPoly([GaussOrthoPoly(2) - for j in 1:length(lb)], - 2)) + op::MultiOrthoPoly = MultiOrthoPoly([GaussOrthoPoly(2) + for j in 1:length(lb)], + 2)) n = length(x) d = length(lb) poly_degree = op.deg @@ -75,7 +75,7 @@ function (pcND::PolynomialChaosSurrogate)(val) sum = sum + pcND.coeff[i] * first(PolyChaos.evaluate(pcND.ortopolys.ind[i, :], collect(val), - pcND.ortopolys)) + pcND.ortopolys)) end return sum end @@ -86,12 +86,12 @@ function add_point!(polych::PolynomialChaosSurrogate, x_new, y_new) polych.x = vcat(polych.x, x_new) polych.y = vcat(polych.y, y_new) polych.coeff = _calculatepce_coeff(polych.x, polych.y, polych.num_of_multi_indexes, - polych.ortopolys) + polych.ortopolys) else polych.x = vcat(polych.x, x_new) polych.y = vcat(polych.y, y_new) polych.coeff = _calculatepce_coeff(polych.x, polych.y, polych.num_of_multi_indexes, - polych.ortopolys) + polych.ortopolys) end nothing end diff --git a/src/Radials.jl b/src/Radials.jl index 88178a899..d60f3ca40 100644 --- a/src/Radials.jl +++ b/src/Radials.jl @@ -25,9 +25,9 @@ cubicRadial() = RadialFunction(1, z -> norm(z)^3) multiquadricRadial(c = 1.0) = RadialFunction(1, z -> sqrt((c * norm(z))^2 + 1)) thinplateRadial() = RadialFunction(2, z -> begin - result = norm(z)^2 * log(norm(z)) - ifelse(iszero(z), zero(result), result) - end) + result = norm(z)^2 * log(norm(z)) + ifelse(iszero(z), zero(result), result) +end) """ RadialBasis(x,y,lb,ub,rad::RadialFunction, scale_factor::Float = 1.0) @@ -45,7 +45,7 @@ https://en.wikipedia.org/wiki/Polyharmonic_spline """ function RadialBasis(x, y, lb, ub; rad::RadialFunction = linearRadial(), - scale_factor::Real = 0.5, sparse = false) + scale_factor::Real = 0.5, sparse = false) q = rad.q phi = rad.phi coeff = _calc_coeffs(x, y, lb, ub, phi, q, scale_factor, sparse) @@ -110,9 +110,9 @@ using Zygote: @nograd, Buffer function _make_combination(n, d, ix) exponents_combinations = [e for e - in collect(Iterators.product(Iterators.repeated(0:n, - d)...))[:] - if sum(e) <= n] + in collect(Iterators.product(Iterators.repeated(0:n, + d)...))[:] + if sum(e) <= n] return exponents_combinations[ix + 1] end @@ -144,7 +144,7 @@ function multivar_poly_basis(x, ix, d, n) else prod(a^d for (a, d) - in zip(x, _make_combination(n, d, ix))) + in zip(x, _make_combination(n, d, ix))) end end @@ -179,12 +179,12 @@ function _add_tmp_to_approx!(approx, i, tmp, rad::RadialBasis; f = identity) end # specialise when only single output dimension function _make_approx(val, - ::RadialBasis{F, Q, X, <:AbstractArray{<:Number}}) where {F, Q, X} + ::RadialBasis{F, Q, X, <:AbstractArray{<:Number}}) where {F, Q, X} return Ref(zero(eltype(val))) end function _add_tmp_to_approx!(approx::Base.RefValue, i, tmp, - rad::RadialBasis{F, Q, X, <:AbstractArray{<:Number}}; - f = identity) where {F, Q, X} + rad::RadialBasis{F, Q, X, <:AbstractArray{<:Number}}; + f = identity) where {F, Q, X} @inbounds @simd ivdep for j in 1:size(rad.coeff, 1) approx[] += rad.coeff[j, i] * f(tmp) end @@ -242,6 +242,6 @@ function add_point!(rad::RadialBasis, new_x, new_y) append!(rad.y, new_y) end rad.coeff = _calc_coeffs(rad.x, rad.y, rad.lb, rad.ub, rad.phi, rad.dim_poly, - rad.scale_factor, rad.sparse) + rad.scale_factor, rad.sparse) nothing end diff --git a/src/Sampling.jl b/src/Sampling.jl index 800f6c5ab..0eda577e0 100644 --- a/src/Sampling.jl +++ b/src/Sampling.jl @@ -6,11 +6,99 @@ using QuasiMonteCarlo: SamplingAlgorithm # of vectors of Tuples function sample(args...; kwargs...) s = QuasiMonteCarlo.sample(args...; kwargs...) - if s isa Vector + if isone(size(s, 1)) # 1D case: s is a Vector - return s + return vec(s) else # ND case: s is a d x n matrix, where d is the dimension and n is the number of samples return collect(reinterpret(reshape, NTuple{size(s, 1), eltype(s)}, s)) end end + +#### SectionSample #### +""" + SectionSample{T}(x0, sa) +`SectionSample(x0, sampler)` where `sampler` is any sampler above and `x0` is a vector of either `NaN` for a free dimension or some scalar for a constrained dimension. +""" +struct SectionSample{ + R <: Real, + I <: Integer, + VR <: AbstractVector{R}, + VI <: AbstractVector{I}, +} <: SamplingAlgorithm + x0::VR + sa::SamplingAlgorithm + fixed_dims::VI +end +fixed_dimensions(section_sampler::SectionSample)::Vector{Int64} = findall(x -> x == false, + isnan.(section_sampler.x0)) +free_dimensions(section_sampler::SectionSample)::Vector{Int64} = findall(x -> x == true, + isnan.(section_sampler.x0)) +""" + sample(n,lb,ub,K::SectionSample) +Returns Tuples constrained to a section. +In surrogate-based identification and control, optimization can alternate between unconstrained sampling in the full-dimensional parameter space, and sampling constrained on specific sections (e.g. a planes in a 3D volume), +A SectionSample allows sampling and optimizing on a subset of 'free' dimensions while keeping 'fixed' ones constrained. +The sampler is defined as in e.g. +`section_sampler_y_is_10 = SectionSample([NaN64, NaN64, 10.0, 10.0], UniformSample())` +where the first argument is a Vector{T} in which numbers are fixed coordinates and `NaN`s correspond to free dimensions, and the second argument is a SamplingAlgorithm which is used to sample in the free dimensions. +""" +function sample(n::Integer, + lb::T, + ub::T, + section_sampler::SectionSample) where { + T <: Union{Base.AbstractVecOrTuple, Number}} + @assert n>0 ZERO_SAMPLES_MESSAGE + QuasiMonteCarlo._check_sequence(lb, ub, length(lb)) + if lb isa Number + if isnan(section_sampler.x0[1]) + return vec(sample(n, lb, ub, section_sampler.sa)) + else + return fill(section_sampler.x0[1], n) + end + else + d_free = free_dimensions(section_sampler) + @info d_free + new_samples = QuasiMonteCarlo.sample(n, lb[d_free], ub[d_free], section_sampler.sa) + out_as_vec = collect(repeat(section_sampler.x0', n, 1)') + + for y in 1:size(out_as_vec, 2) + for (xi, d) in enumerate(d_free) + out_as_vec[d, y] = new_samples[xi, y] + end + end + return isone(size(out_as_vec, 1)) ? vec(out_as_vec) : + collect(reinterpret(reshape, + NTuple{size(out_as_vec, 1), eltype(out_as_vec)}, + out_as_vec)) + end +end + +function SectionSample(x0::AbstractVector, sa::SamplingAlgorithm) + SectionSample(x0, sa, findall(isnan, x0)) +end + +""" + SectionSample(n, d, K::SectionSample) +In surrogate-based identification and control, optimization can alternate between unconstrained sampling in the full-dimensional parameter space, and sampling constrained on specific sections (e.g. planes in a 3D volume). +`SectionSample` allows sampling and optimizing on a subset of 'free' dimensions while keeping 'fixed' ones constrained. +The sampler is defined +`SectionSample([NaN64, NaN64, 10.0, 10.0], UniformSample())` +where the first argument is a Vector{T} in which numbers are fixed coordinates and `NaN`s correspond to free dimensions, and the second argument is a SamplingAlgorithm which is used to sample in the free dimensions. +""" +function sample(n::Integer, + d::Integer, + section_sampler::SectionSample, + T = eltype(section_sampler.x0)) + QuasiMonteCarlo._check_sequence(n) + @assert eltype(section_sampler.x0) == T + @assert length(section_sampler.fixed_dims) == d + return sample(n, section_sampler) +end + +@views function sample(n::Integer, section_sampler::SectionSample{T}) where {T} + samples = Matrix{T}(undef, n, length(section_sampler.x0)) + fixed_dims = section_sampler.fixed_dims + samples[:, fixed_dims] .= sample(n, length(fixed_dims), section_sampler.sa, T) + return vec(samples) +end diff --git a/src/Surrogates.jl b/src/Surrogates.jl index 45df925b3..0d388a6a4 100755 --- a/src/Surrogates.jl +++ b/src/Surrogates.jl @@ -28,7 +28,7 @@ current_surrogates = ["Kriging", "LinearSurrogate", "LobachevskySurrogate", #Radial structure: function RadialBasisStructure(; radial_function, scale_factor, sparse) return (name = "RadialBasis", radial_function = radial_function, - scale_factor = scale_factor, sparse = sparse) + scale_factor = scale_factor, sparse = sparse) end #Kriging structure: @@ -58,7 +58,7 @@ end #Neural structure function NeuralStructure(; model, loss, opt, n_echos) return (name = "NeuralSurrogate", model = model, loss = loss, opt = opt, - n_echos = n_echos) + n_echos = n_echos) end #Random forest structure @@ -84,22 +84,23 @@ end export current_surrogates export GEKPLS export RadialBasisStructure, KrigingStructure, LinearStructure, InverseDistanceStructure -export LobachevskyStructure, NeuralStructure, RandomForestStructure, - SecondOrderPolynomialStructure +export LobachevskyStructure, + NeuralStructure, RandomForestStructure, + SecondOrderPolynomialStructure export WendlandStructure export AbstractSurrogate, SamplingAlgorithm export Kriging, RadialBasis, add_point!, current_estimate, std_error_at_point # Parallelization Strategies export potential_optimal_points export MinimumConstantLiar, MaximumConstantLiar, MeanConstantLiar, KrigingBeliever, - KrigingBelieverUpperBound, KrigingBelieverLowerBound + KrigingBelieverUpperBound, KrigingBelieverLowerBound # radial basis functions export linearRadial, cubicRadial, multiquadricRadial, thinplateRadial # samplers -export sample, GridSample, UniformSample, SobolSample, LatinHypercubeSample, - LowDiscrepancySample +export sample, GridSample, RandomSample, SobolSample, LatinHypercubeSample, + HaltonSample export RandomSample, KroneckerSample, GoldenSample, SectionSample # Optimization algorithms @@ -111,8 +112,9 @@ export InverseDistanceSurrogate export SecondOrderPolynomialSurrogate export Wendland export RadialBasisStructure, KrigingStructure, LinearStructure, InverseDistanceStructure -export LobachevskyStructure, NeuralStructure, RandomForestStructure, - SecondOrderPolynomialStructure +export LobachevskyStructure, + NeuralStructure, RandomForestStructure, + SecondOrderPolynomialStructure export WendlandStructure #export MOE export VariableFidelitySurrogate diff --git a/src/VariableFidelity.jl b/src/VariableFidelity.jl index de713c770..d90928d38 100644 --- a/src/VariableFidelity.jl +++ b/src/VariableFidelity.jl @@ -9,13 +9,13 @@ mutable struct VariableFidelitySurrogate{X, Y, L, U, N, F, E} <: AbstractSurroga end function VariableFidelitySurrogate(x, y, lb, ub; - num_high_fidel = Int(floor(length(x) / 2)), - low_fid_structure = RadialBasisStructure(radial_function = linearRadial(), - scale_factor = 1.0, - sparse = false), - high_fid_structure = RadialBasisStructure(radial_function = cubicRadial(), - scale_factor = 1.0, - sparse = false)) + num_high_fidel = Int(floor(length(x) / 2)), + low_fid_structure = RadialBasisStructure(radial_function = linearRadial(), + scale_factor = 1.0, + sparse = false), + high_fid_structure = RadialBasisStructure(radial_function = cubicRadial(), + scale_factor = 1.0, + sparse = false)) x_high = x[1:num_high_fidel] x_low = x[(num_high_fidel + 1):end] y_high = y[1:num_high_fidel] @@ -25,48 +25,48 @@ function VariableFidelitySurrogate(x, y, lb, ub; if low_fid_structure[1] == "RadialBasis" #fit and append to local_surr low_fid_surr = RadialBasis(x_low, y_low, lb, ub, - rad = low_fid_structure.radial_function, - scale_factor = low_fid_structure.scale_factor, - sparse = low_fid_structure.sparse) + rad = low_fid_structure.radial_function, + scale_factor = low_fid_structure.scale_factor, + sparse = low_fid_structure.sparse) elseif low_fid_structure[1] == "Kriging" low_fid_surr = Kriging(x_low, y_low, lb, ub, p = low_fid_structure.p, - theta = low_fid_structure.theta) + theta = low_fid_structure.theta) elseif low_fid_structure[1] == "GEK" low_fid_surr = GEK(x_low, y_low, lb, ub, p = low_fid_structure.p, - theta = low_fid_structure.theta) + theta = low_fid_structure.theta) elseif low_fid_structure == "LinearSurrogate" low_fid_surr = LinearSurrogate(x_low, y_low, lb, ub) elseif low_fid_structure[1] == "InverseDistanceSurrogate" low_fid_surr = InverseDistanceSurrogate(x_low, y_low, lb, ub, - p = low_fid_structure.p) + p = low_fid_structure.p) elseif low_fid_structure[1] == "LobachevskySurrogate" low_fid_surr = LobachevskySurrogate(x_low, y_low, lb, ub, - alpha = low_fid_structure.alpha, - n = low_fid_structure.n, - sparse = low_fid_structure.sparse) + alpha = low_fid_structure.alpha, + n = low_fid_structure.n, + sparse = low_fid_structure.sparse) elseif low_fid_structure[1] == "NeuralSurrogate" low_fid_surr = NeuralSurrogate(x_low, y_low, lb, ub, - model = low_fid_structure.model, - loss = low_fid_structure.loss, - opt = low_fid_structure.opt, - n_echos = low_fid_structure.n_echos) + model = low_fid_structure.model, + loss = low_fid_structure.loss, + opt = low_fid_structure.opt, + n_echos = low_fid_structure.n_echos) elseif low_fid_structure[1] == "RandomForestSurrogate" low_fid_surr = RandomForestSurrogate(x_low, y_low, lb, ub, - num_round = low_fid_structure.num_round) + num_round = low_fid_structure.num_round) elseif low_fid_structure == "SecondOrderPolynomialSurrogate" low_fid_surr = SecondOrderPolynomialSurrogate(x_low, y_low, lb, ub) elseif low_fid_structure[1] == "Wendland" low_fid_surr = Wendand(x_low, y_low, lb, ub, eps = low_fid_surr.eps, - maxiters = low_fid_surr.maxiters, tol = low_fid_surr.tol) + maxiters = low_fid_surr.maxiters, tol = low_fid_surr.tol) else throw("A surrogate with the name provided does not exist or is not currently supported with VariableFidelity") end @@ -80,12 +80,12 @@ function VariableFidelitySurrogate(x, y, lb, ub; if high_fid_structure[1] == "RadialBasis" #fit and append to local_surr eps = RadialBasis(x_high, y_eps, lb, ub, rad = high_fid_structure.radial_function, - scale_factor = high_fid_structure.scale_factor, - sparse = high_fid_structure.sparse) + scale_factor = high_fid_structure.scale_factor, + sparse = high_fid_structure.sparse) elseif high_fid_structure[1] == "Kriging" eps = Kriging(x_high, y_eps, lb, ub, p = high_fid_structure.p, - theta = high_fid_structure.theta) + theta = high_fid_structure.theta) elseif high_fid_structure == "LinearSurrogate" eps = LinearSurrogate(x_high, y_eps, lb, ub) @@ -95,24 +95,24 @@ function VariableFidelitySurrogate(x, y, lb, ub; elseif high_fid_structure[1] == "LobachevskySurrogate" eps = LobachevskySurrogate(x_high, y_eps, lb, ub, alpha = high_fid_structure.alpha, - n = high_fid_structure.n, - sparse = high_fid_structure.sparse) + n = high_fid_structure.n, + sparse = high_fid_structure.sparse) elseif high_fid_structure[1] == "NeuralSurrogate" eps = NeuralSurrogate(x_high, y_eps, lb, ub, model = high_fid_structure.model, - loss = high_fid_structure.loss, opt = high_fid_structure.opt, - n_echos = high_fid_structure.n_echos) + loss = high_fid_structure.loss, opt = high_fid_structure.opt, + n_echos = high_fid_structure.n_echos) elseif high_fid_structure[1] == "RandomForestSurrogate" eps = RandomForestSurrogate(x_high, y_eps, lb, ub, - num_round = high_fid_structure.num_round) + num_round = high_fid_structure.num_round) elseif high_fid_structure == "SecondOrderPolynomialSurrogate" eps = SecondOrderPolynomialSurrogate(x_high, y_eps, lb, ub) elseif high_fid_structure[1] == "Wendland" eps = Wendand(x_high, y_eps, lb, ub, eps = high_fid_structure.eps, - maxiters = high_fid_structure.maxiters, tol = high_fid_structure.tol) + maxiters = high_fid_structure.maxiters, tol = high_fid_structure.tol) else throw("A surrogate with the name provided does not exist or is not currently supported with VariableFidelity") end diff --git a/src/VirtualStrategy.jl b/src/VirtualStrategy.jl index cc63a0c19..33ce1877a 100644 --- a/src/VirtualStrategy.jl +++ b/src/VirtualStrategy.jl @@ -1,17 +1,26 @@ # Minimum Constant Liar -function calculate_liars(::MinimumConstantLiar, tmp_surr::AbstractSurrogate, surr::AbstractSurrogate, new_x) +function calculate_liars(::MinimumConstantLiar, + tmp_surr::AbstractSurrogate, + surr::AbstractSurrogate, + new_x) new_y = minimum(surr.y) add_point!(tmp_surr, new_x, new_y) end # Maximum Constant Liar -function calculate_liars(::MaximumConstantLiar, tmp_surr::AbstractSurrogate, surr::AbstractSurrogate, new_x) +function calculate_liars(::MaximumConstantLiar, + tmp_surr::AbstractSurrogate, + surr::AbstractSurrogate, + new_x) new_y = maximum(surr.y) add_point!(tmp_surr, new_x, new_y) end # Mean Constant Liar -function calculate_liars(::MeanConstantLiar, tmp_surr::AbstractSurrogate, surr::AbstractSurrogate, new_x) +function calculate_liars(::MeanConstantLiar, + tmp_surr::AbstractSurrogate, + surr::AbstractSurrogate, + new_x) new_y = mean(surr.y) add_point!(tmp_surr, new_x, new_y) end @@ -32,4 +41,4 @@ end function calculate_liars(::KrigingBelieverLowerBound, tmp_k::Kriging, k::Kriging, new_x) new_y = k(new_x) - 3 * std_error_at_point(k, new_x) add_point!(tmp_k, new_x, new_y) -end \ No newline at end of file +end diff --git a/test/GEKPLS.jl b/test/GEKPLS.jl index 612792d81..2c2aadf1d 100644 --- a/test/GEKPLS.jl +++ b/test/GEKPLS.jl @@ -88,7 +88,7 @@ y_true = welded_beam.(x_test) g = GEKPLS(x, y, grads, n_comp, delta_x, lb, ub, extra_points, initial_theta) y_pred = g.(x_test) rmse = sqrt(sum(((y_pred - y_true) .^ 2) / n_test)) - @test isapprox(rmse, 39.0, atol = 0.5) #rmse: 38.988 + @test isapprox(rmse, 50.0, atol = 0.5)#rmse: 38.988 end @testset "Test 5: Welded Beam Function Test (dimensions = 3; n_comp = 2; extra_points = 2)" begin @@ -99,7 +99,7 @@ end g = GEKPLS(x, y, grads, n_comp, delta_x, lb, ub, extra_points, initial_theta) y_pred = g.(x_test) rmse = sqrt(sum(((y_pred - y_true) .^ 2) / n_test)) - @test isapprox(rmse, 39.5, atol = 0.5) #rmse: 39.481 + @test isapprox(rmse, 51.0, atol = 0.5) #rmse: 39.481 end ## increasing extra points increases accuracy @@ -111,7 +111,7 @@ end g = GEKPLS(x, y, grads, n_comp, delta_x, lb, ub, extra_points, initial_theta) y_pred = g.(x_test) rmse = sqrt(sum(((y_pred - y_true) .^ 2) / n_test)) - @test isapprox(rmse, 37.5, atol = 0.5) #rmse: 37.87 + @test isapprox(rmse, 49.0, atol = 0.5) #rmse: 37.87 end ## sphere function tests @@ -175,8 +175,8 @@ end extra_points = 2 initial_theta = [0.01 for i in 1:n_comp] g = GEKPLS(initial_x_vec, initial_y, initial_grads, n_comp, delta_x, lb, ub, - extra_points, - initial_theta) + extra_points, + initial_theta) n_test = 100 x_test = sample(n_test, lb, ub, GoldenSample()) y_true = sphere_function.(x_test) @@ -209,17 +209,17 @@ end y = sphere_function.(x) g = GEKPLS(x, y, grads, n_comp, delta_x, lb, ub, extra_points, initial_theta) x_point, minima = surrogate_optimize(sphere_function, SRBF(), lb, ub, g, - UniformSample(); maxiters = 20, - num_new_samples = 20, needs_gradient = true) + RandomSample(); maxiters = 20, + num_new_samples = 20, needs_gradient = true) @test isapprox(minima, 0.0, atol = 0.0001) end -@testset "Test 11: Check gradient (dimensions = 3; n_comp = 2; extra_points = 2)" begin +@testset "Test 11: Check gradient (dimensions = 3; n_comp = 2; extra_points = 3)" begin lb = [-5.0, -5.0, -5.0] ub = [10.0, 10.0, 10.0] n_comp = 2 delta_x = 0.0001 - extra_points = 2 + extra_points = 3 initial_theta = [0.01 for i in 1:n_comp] n = 100 x = sample(n, lb, ub, SobolSample()) diff --git a/test/MOE.jl b/test/MOE.jl index 442c84292..26eb458e5 100644 --- a/test/MOE.jl +++ b/test/MOE.jl @@ -5,7 +5,7 @@ using Surrogates n = 30 lb = 0.0 ub = 5.0 -x = Surrogates.sample(n,lb,ub,UniformSample()) +x = Surrogates.sample(n,lb,ub,RandomSample()) f = x-> 2*x y = f.(x) #Standard definition diff --git a/test/Radials.jl b/test/Radials.jl index c0e40449e..3852f7cd3 100644 --- a/test/Radials.jl +++ b/test/Radials.jl @@ -157,7 +157,7 @@ mq_rad = RadialBasis(x, y, lb, ub, rad = multiquadricRadial(0.9)) # different sh # Issue 316 -x = sample(1024, [-0.45 -0.4 -0.9], [0.40 0.55 0.35], SobolSample()) +x = sample(1024, [-0.45, -0.4, -0.9], [0.40, 0.55, 0.35], SobolSample()) lb = [-0.45 -0.4 -0.9] ub = [0.40 0.55 0.35] diff --git a/test/SectionSampleTests.jl b/test/SectionSampleTests.jl index f0a909cd4..be6d656c8 100644 --- a/test/SectionSampleTests.jl +++ b/test/SectionSampleTests.jl @@ -25,26 +25,26 @@ isapprox(f([0, 0, 0]), f_hat([0, 0, 0])) """ The global minimum is at (0,0) """ (xy_min, f_hat_min) = surrogate_optimize(f, - DYCORS(), lb, ub, - f_hat, - SobolSample()) + DYCORS(), lb, ub, + f_hat, + SobolSample()) isapprox(xy_min[1], 0.0, atol = 1e-1) """ The minimum on the (0,10) section is around (0,10) """ section_sampler_z_is_10 = SectionSample([NaN64, NaN64, 10.0], - Surrogates.UniformSample()) + Surrogates.RandomSample()) -@test [3] == QuasiMonteCarlo.fixed_dimensions(section_sampler_z_is_10) -@test [1, 2] == QuasiMonteCarlo.free_dimensions(section_sampler_z_is_10) +@test [3] == Surrogates.fixed_dimensions(section_sampler_z_is_10) +@test [1, 2] == Surrogates.free_dimensions(section_sampler_z_is_10) Surrogates.sample(5, lb, ub, section_sampler_z_is_10) (xy_min, f_hat_min) = surrogate_optimize(f, - EI(), lb, ub, - f_hat, - section_sampler_z_is_10, maxiters = 1000) + EI(), lb, ub, + f_hat, + section_sampler_z_is_10, maxiters = 1000) isapprox(xy_min[1], 0.0, atol = 0.1) isapprox(xy_min[2], 0.0, atol = 0.1) diff --git a/test/VariableFidelity.jl b/test/VariableFidelity.jl index 378c7b843..fe1cd49f1 100644 --- a/test/VariableFidelity.jl +++ b/test/VariableFidelity.jl @@ -13,10 +13,10 @@ add_point!(my_varfid, 3.0, 6.0) val = my_varfid(3.0) my_varfid_change_struct = VariableFidelitySurrogate(x, y, lb, ub, num_high_fidel = 2, - low_fid_structure = InverseDistanceStructure(p = 1.0), - high_fid_structure = RadialBasisStructure(radial_function = linearRadial(), - scale_factor = 1.0, - sparse = false)) + low_fid_structure = InverseDistanceStructure(p = 1.0), + high_fid_structure = RadialBasisStructure(radial_function = linearRadial(), + scale_factor = 1.0, + sparse = false)) #ND n = 10 lb = [0.0, 0.0] @@ -28,7 +28,7 @@ my_varfidND = VariableFidelitySurrogate(x, y, lb, ub) val = my_varfidND((2.0, 2.0)) add_point!(my_varfidND, (3.0, 3.0), 9.0) my_varfidND_change_struct = VariableFidelitySurrogate(x, y, lb, ub, num_high_fidel = 2, - low_fid_structure = InverseDistanceStructure(p = 1.0), - high_fid_structure = RadialBasisStructure(radial_function = linearRadial(), - scale_factor = 1.0, - sparse = false)) + low_fid_structure = InverseDistanceStructure(p = 1.0), + high_fid_structure = RadialBasisStructure(radial_function = linearRadial(), + scale_factor = 1.0, + sparse = false)) diff --git a/test/inverseDistanceSurrogate.jl b/test/inverseDistanceSurrogate.jl index c0fc30f7a..f49bc805e 100644 --- a/test/inverseDistanceSurrogate.jl +++ b/test/inverseDistanceSurrogate.jl @@ -1,11 +1,11 @@ using Surrogates using Test - +using QuasiMonteCarlo #1D obj = x -> sin(x) + sin(x)^2 + sin(x)^3 lb = 0.0 ub = 10.0 -x = sample(5, lb, ub, LowDiscrepancySample(2)) +x = sample(5, lb, ub, HaltonSample()) y = obj.(x) p = 3.5 InverseDistance = InverseDistanceSurrogate(x, y, lb, ub, p = 2.4) diff --git a/test/optimization.jl b/test/optimization.jl index 149164722..85492edc5 100644 --- a/test/optimization.jl +++ b/test/optimization.jl @@ -1,6 +1,6 @@ using Surrogates using LinearAlgebra - +using QuasiMonteCarlo #######SRBF############ ##### 1D ##### @@ -23,7 +23,7 @@ x = [2.5, 4.0, 6.0] y = [6.0, 9.0, 13.0] my_k_SRBF1 = Kriging(x, y, lb, ub; p) xstar, fstar = surrogate_optimize(objective_function, SRBF(), a, b, my_k_SRBF1, - UniformSample()) + RandomSample()) #Using RadialBasis @@ -31,19 +31,19 @@ x = [2.5, 4.0, 6.0] y = [6.0, 9.0, 13.0] my_rad_SRBF1 = RadialBasis(x, y, a, b, rad = linearRadial()) (xstar, fstar) = surrogate_optimize(objective_function, SRBF(), a, b, my_rad_SRBF1, - UniformSample()) + RandomSample()) x = [2.5, 4.0, 6.0] y = [6.0, 9.0, 13.0] my_wend_1d = Wendland(x, y, lb, ub) xstar, fstar = surrogate_optimize(objective_function, SRBF(), a, b, my_wend_1d, - UniformSample()) + RandomSample()) x = [2.5, 4.0, 6.0] y = [6.0, 9.0, 13.0] my_earth1d = EarthSurrogate(x, y, lb, ub) xstar, fstar = surrogate_optimize(objective_function, SRBF(), a, b, my_earth1d, - LowDiscrepancySample(2)) + HaltonSample()) ##### ND ##### objective_function_ND = z -> 3 * norm(z) + 1 @@ -57,7 +57,7 @@ y = objective_function_ND.(x) my_k_SRBFN = Kriging(x, y, lb, ub) #Every optimization method now returns the y_min and its position x_min, y_min = surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_k_SRBFN, - UniformSample()) + RandomSample()) #Radials lb = [1.0, 1.0] @@ -66,15 +66,15 @@ x = sample(5, lb, ub, SobolSample()) objective_function_ND = z -> 3 * norm(z) + 1 y = objective_function_ND.(x) my_rad_SRBFN = RadialBasis(x, y, lb, ub, rad = linearRadial()) -surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_rad_SRBFN, UniformSample()) +surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_rad_SRBFN, RandomSample()) # Lobachevsky -x = sample(5, lb, ub, UniformSample()) +x = sample(5, lb, ub, RandomSample()) y = objective_function_ND.(x) alpha = [2.0, 2.0] n = 4 my_loba_ND = LobachevskySurrogate(x, y, lb, ub) -surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_loba_ND, UniformSample()) +surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_loba_ND, RandomSample()) #Linear lb = [1.0, 1.0] @@ -84,7 +84,7 @@ objective_function_ND = z -> 3 * norm(z) + 1 y = objective_function_ND.(x) my_linear_ND = LinearSurrogate(x, y, lb, ub) surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_linear_ND, SobolSample(), - maxiters = 15) + maxiters = 15) #= #SVM @@ -106,17 +106,17 @@ my_p = 2.5 y = objective_function_ND.(x) my_inverse_ND = InverseDistanceSurrogate(x, y, lb, ub, p = my_p) surrogate_optimize(objective_function_ND, SRBF(), lb, ub, my_inverse_ND, SobolSample(), - maxiters = 15) + maxiters = 15) #SecondOrderPolynomialSurrogate lb = [0.0, 0.0] ub = [10.0, 10.0] obj_ND = x -> log(x[1]) * exp(x[2]) -x = sample(15, lb, ub, UniformSample()) +x = sample(15, lb, ub, RandomSample()) y = obj_ND.(x) my_second_order_poly_ND = SecondOrderPolynomialSurrogate(x, y, lb, ub) surrogate_optimize(obj_ND, SRBF(), lb, ub, my_second_order_poly_ND, SobolSample(), - maxiters = 15) + maxiters = 15) ####### LCBS ######### ######1D###### @@ -129,7 +129,7 @@ p = 1.8 a = 2.0 b = 6.0 my_k_LCBS1 = Kriging(x, y, lb, ub) -surrogate_optimize(objective_function, LCBS(), a, b, my_k_LCBS1, UniformSample()) +surrogate_optimize(objective_function, LCBS(), a, b, my_k_LCBS1, RandomSample()) ##### ND ##### objective_function_ND = z -> 3 * norm(z) + 1 @@ -142,7 +142,7 @@ ub = [6.0, 6.0] #Kriging my_k_LCBSN = Kriging(x, y, lb, ub) -surrogate_optimize(objective_function_ND, LCBS(), lb, ub, my_k_LCBSN, UniformSample()) +surrogate_optimize(objective_function_ND, LCBS(), lb, ub, my_k_LCBSN, RandomSample()) ##### EI ###### @@ -156,7 +156,7 @@ x = sample(5, lb, ub, SobolSample()) y = objective_function.(x) my_k_EI1 = Kriging(x, y, lb, ub; p = 2) surrogate_optimize(objective_function, EI(), lb, ub, my_k_EI1, SobolSample(), - maxiters = 200, num_new_samples = 155) + maxiters = 200, num_new_samples = 155) # Check that EI is correctly minimizing the objective y_min, index_min = findmin(my_k_EI1.y) @@ -225,10 +225,10 @@ lb = 2.0 ub = 6.0 my_k_DYCORS1 = Kriging(x, y, lb, ub, p = 1.9) -surrogate_optimize(objective_function, DYCORS(), lb, ub, my_k_DYCORS1, UniformSample()) +surrogate_optimize(objective_function, DYCORS(), lb, ub, my_k_DYCORS1, RandomSample()) my_rad_DYCORS1 = RadialBasis(x, y, lb, ub, rad = linearRadial()) -surrogate_optimize(objective_function, DYCORS(), lb, ub, my_rad_DYCORS1, UniformSample()) +surrogate_optimize(objective_function, DYCORS(), lb, ub, my_rad_DYCORS1, RandomSample()) #ND# objective_function_ND = z -> 2 * norm(z) + 1 @@ -240,16 +240,16 @@ lb = [1.0, 1.0] ub = [6.0, 6.0] my_k_DYCORSN = Kriging(x, y, lb, ub) -surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_k_DYCORSN, UniformSample(), - maxiters = 30) +surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_k_DYCORSN, RandomSample(), + maxiters = 30) my_rad_DYCORSN = RadialBasis(x, y, lb, ub, rad = linearRadial()) -surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_rad_DYCORSN, UniformSample(), - maxiters = 30) +surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_rad_DYCORSN, RandomSample(), + maxiters = 30) my_wend_ND = Wendland(x, y, lb, ub) -surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_wend_ND, UniformSample(), - maxiters = 30) +surrogate_optimize(objective_function_ND, DYCORS(), lb, ub, my_wend_ND, RandomSample(), + maxiters = 30) ### SOP ### # 1D @@ -262,7 +262,7 @@ ub = 6.0 num_centers = 2 my_k_SOP1 = Kriging(x, y, lb, ub, p = 1.9) surrogate_optimize(objective_function, SOP(num_centers), lb, ub, my_k_SOP1, SobolSample(), - maxiters = 60) + maxiters = 60) #ND objective_function_ND = z -> 2 * norm(z) + 1 x = [(2.3, 2.2), (1.4, 1.5)] @@ -274,7 +274,7 @@ ub = [6.0, 6.0] my_k_SOPND = Kriging(x, y, lb, ub) num_centers = 2 surrogate_optimize(objective_function_ND, SOP(num_centers), lb, ub, my_k_SOPND, - SobolSample(), maxiters = 20) + SobolSample(), maxiters = 20) #multi optimization #= diff --git a/test/parallel.jl b/test/parallel.jl index 7cc133e52..f3472b958 100755 --- a/test/parallel.jl +++ b/test/parallel.jl @@ -1,7 +1,6 @@ using Surrogates using Test -using Revise - +using Revise #1D lb = 0.0 @@ -10,13 +9,18 @@ f = x -> log(x) * exp(x) x = sample(5, lb, ub, SobolSample()) y = f.(x) - # Test lengths of new_x and EI (1D) # TODO my_k = Kriging(x, y, lb, ub) -new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, SobolSample(), 3) +new_x, eis = potential_optimal_points(EI(), + MeanConstantLiar(), + lb, + ub, + my_k, + SobolSample(), + 3) @test length(new_x) == 3 @test length(eis) == 3 @@ -24,11 +28,16 @@ new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, So # Test lengths of new_x and SRBF (1D) my_surr = RadialBasis(x, y, lb, ub) -new_x, eis = potential_optimal_points(SRBF(), MeanConstantLiar(), lb, ub, my_surr, SobolSample(), 3) +new_x, eis = potential_optimal_points(SRBF(), + MeanConstantLiar(), + lb, + ub, + my_surr, + SobolSample(), + 3) @test length(new_x) == 3 @test length(eis) == 3 - # Test lengths of new_x and EI (ND) lb = [0.0, 0.0, 1.0] @@ -39,7 +48,13 @@ y = f.(x) my_k = Kriging(x, y, lb, ub) -new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, SobolSample(), 5) +new_x, eis = potential_optimal_points(EI(), + MeanConstantLiar(), + lb, + ub, + my_k, + SobolSample(), + 5) @test length(new_x) == 5 @test length(eis) == 5 @@ -49,7 +64,13 @@ new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, So # Test lengths of new_x and SRBF (ND) my_surr = RadialBasis(x, y, lb, ub) -new_x, eis = potential_optimal_points(SRBF(), MeanConstantLiar(), lb, ub, my_surr, SobolSample(), 5) +new_x, eis = potential_optimal_points(SRBF(), + MeanConstantLiar(), + lb, + ub, + my_surr, + SobolSample(), + 5) @test length(new_x) == 5 @test length(eis) == 5 @@ -57,5 +78,10 @@ new_x, eis = potential_optimal_points(SRBF(), MeanConstantLiar(), lb, ub, my_sur @test length(new_x[1]) == 3 # # Check hyperparameter validation for potential_optimal_points -@test_throws ArgumentError new_x, eis = potential_optimal_points(EI(), MeanConstantLiar(), lb, ub, my_k, SobolSample(), -1) - +@test_throws ArgumentError new_x, eis=potential_optimal_points(EI(), + MeanConstantLiar(), + lb, + ub, + my_k, + SobolSample(), + -1) diff --git a/test/runtests.jl b/test/runtests.jl index 25abaf606..b94a25ac8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -2,7 +2,7 @@ using Surrogates using Test using SafeTestsets using Pkg -VERSION <= v"1.7" && Pkg.add(name="Statistics", version=VERSION) +VERSION <= v"1.7" && Pkg.add(name = "Statistics", version = VERSION) function dev_subpkg(subpkg) subpkg_path = joinpath(dirname(@__DIR__), "lib", subpkg) @@ -22,20 +22,48 @@ end end end @testset "Algorithms" begin - @time @safetestset "GEKPLS" begin include("GEKPLS.jl") end - @time @safetestset "Radials" begin include("Radials.jl") end - @time @safetestset "Kriging" begin include("Kriging.jl") end - @time @safetestset "Sampling" begin include("sampling.jl") end - @time @safetestset "Optimization" begin include("optimization.jl") end - @time @safetestset "LinearSurrogate" begin include("linearSurrogate.jl") end - @time @safetestset "Lobachevsky" begin include("lobachevsky.jl") end - @time @safetestset "InverseDistanceSurrogate" begin include("inverseDistanceSurrogate.jl") end - @time @safetestset "SecondOrderPolynomialSurrogate" begin include("secondOrderPolynomialSurrogate.jl") end + @time @safetestset "GEKPLS" begin + include("GEKPLS.jl") + end + @time @safetestset "Radials" begin + include("Radials.jl") + end + @time @safetestset "Kriging" begin + include("Kriging.jl") + end + @time @safetestset "Sampling" begin + include("sampling.jl") + end + @time @safetestset "Optimization" begin + include("optimization.jl") + end + @time @safetestset "LinearSurrogate" begin + include("linearSurrogate.jl") + end + @time @safetestset "Lobachevsky" begin + include("lobachevsky.jl") + end + @time @safetestset "InverseDistanceSurrogate" begin + include("inverseDistanceSurrogate.jl") + end + @time @safetestset "SecondOrderPolynomialSurrogate" begin + include("secondOrderPolynomialSurrogate.jl") + end # @time @safetestset "AD_Compatibility" begin include("AD_compatibility.jl") end - @time @safetestset "Wendland" begin include("Wendland.jl") end - @time @safetestset "VariableFidelity" begin include("VariableFidelity.jl") end - @time @safetestset "Earth" begin include("earth.jl") end - @time @safetestset "Gradient Enhanced Kriging" begin include("GEK.jl") end - @time @safetestset "Section Samplers" begin include("SectionSampleTests.jl") end + @time @safetestset "Wendland" begin + include("Wendland.jl") + end + @time @safetestset "VariableFidelity" begin + include("VariableFidelity.jl") + end + @time @safetestset "Earth" begin + include("earth.jl") + end + @time @safetestset "Gradient Enhanced Kriging" begin + include("GEK.jl") + end + @time @safetestset "Section Samplers" begin + include("SectionSampleTests.jl") + end end -end \ No newline at end of file +end diff --git a/test/sampling.jl b/test/sampling.jl index e89df8089..6f1dbcf0f 100644 --- a/test/sampling.jl +++ b/test/sampling.jl @@ -1,6 +1,6 @@ using Surrogates using QuasiMonteCarlo -using QuasiMonteCarlo: KroneckerSample, SectionSample, GoldenSample +using QuasiMonteCarlo: KroneckerSample, GoldenSample using Distributions: Cauchy, Normal using Test @@ -13,11 +13,11 @@ d = 1 ## Sampling methods from QuasiMonteCarlo.jl ## # GridSample -s = Surrogates.sample(n, lb, ub, GridSample(0.1)) +s = Surrogates.sample(n, lb, ub, GridSample()) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) -# UniformSample -s = Surrogates.sample(n, lb, ub, UniformSample()) +# RandomSample +s = Surrogates.sample(n, lb, ub, RandomSample()) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) # SobolSample @@ -29,7 +29,7 @@ s = Surrogates.sample(n, lb, ub, LatinHypercubeSample()) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) # LowDiscrepancySample -s = Surrogates.sample(20, lb, ub, LowDiscrepancySample(; base = 10)) +s = Surrogates.sample(20, lb, ub, HaltonSample()) @test s isa Vector{Float64} && length(s) == 20 && all(x -> lb ≤ x ≤ ub, s) # LatticeRuleSample (not originally in Surrogates.jl, now available through QuasiMonteCarlo.jl) @@ -47,7 +47,7 @@ s = Surrogates.sample(n, d, Normal(0, 4)) ## Sampling methods specific to Surrogates.jl ## # KroneckerSample -s = Surrogates.sample(n, lb, ub, KroneckerSample(sqrt(2), 0)) +s = Surrogates.sample(n, lb, ub, KroneckerSample([sqrt(2)], NoRand())) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) # GoldenSample @@ -56,10 +56,10 @@ s = Surrogates.sample(n, lb, ub, GoldenSample()) # SectionSample constrained_val = 1.0 -s = Surrogates.sample(n, lb, ub, SectionSample([NaN64], UniformSample())) +s = Surrogates.sample(n, lb, ub, SectionSample([NaN64], RandomSample())) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) -s = Surrogates.sample(n, lb, ub, SectionSample([constrained_val], UniformSample())) +s = Surrogates.sample(n, lb, ub, SectionSample([constrained_val], RandomSample())) @test s isa Vector{Float64} && length(s) == n && all(x -> lb ≤ x ≤ ub, s) @test all(==(constrained_val), s) @@ -73,11 +73,11 @@ n = 5 d = 2 #GridSample{T} -s = Surrogates.sample(n, lb, ub, GridSample([0.1, 0.5])) +s = Surrogates.sample(n, lb, ub, GridSample()) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true -#UniformSample() -s = Surrogates.sample(n, lb, ub, UniformSample()) +#RandomSample() +s = Surrogates.sample(n, lb, ub, RandomSample()) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true #SobolSample() @@ -89,7 +89,7 @@ s = Surrogates.sample(n, lb, ub, LatinHypercubeSample()) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true #LDS -s = Surrogates.sample(n, lb, ub, LowDiscrepancySample(; base = [10, 3])) +s = Surrogates.sample(n, lb, ub, HaltonSample()) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true #Distribution 1 @@ -101,7 +101,7 @@ s = Surrogates.sample(n, d, Normal(3, 5)) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true #Kronecker -s = Surrogates.sample(n, lb, ub, KroneckerSample([sqrt(2), 3.1415], [0, 0])) +s = Surrogates.sample(n, lb, ub, KroneckerSample([sqrt(2), 3.1415], NoRand())) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true #Golden @@ -110,7 +110,7 @@ s = Surrogates.sample(n, lb, ub, GoldenSample()) # SectionSample constrained_val = 1.0 -s = Surrogates.sample(n, lb, ub, SectionSample([NaN64, constrained_val], UniformSample())) +s = Surrogates.sample(n, lb, ub, SectionSample([NaN64, constrained_val], RandomSample())) @test all(x -> x[end] == constrained_val, s) @test isa(s, Array{Tuple{typeof(s[1][1]), typeof(s[1][1])}, 1}) == true @test all(x -> lb[1] ≤ x[1] ≤ ub[1], s) diff --git a/test/secondOrderPolynomialSurrogate.jl b/test/secondOrderPolynomialSurrogate.jl index e1b1f655a..1b2e90d35 100644 --- a/test/secondOrderPolynomialSurrogate.jl +++ b/test/secondOrderPolynomialSurrogate.jl @@ -20,7 +20,7 @@ add_point!(my_second_order_poly, [6.0, 7.0], [722.84, 2133.94]) lb = [0.0, 0.0] ub = [10.0, 10.0] obj_ND = x -> log(x[1]) * exp(x[2]) -x = sample(10, lb, ub, UniformSample()) +x = sample(10, lb, ub, RandomSample()) y = obj_ND.(x) my_second_order_poly = SecondOrderPolynomialSurrogate(x, y, lb, ub) val = my_second_order_poly((5.0, 7.0))