Skip to content

Commit 51202f6

Browse files
Merge pull request #509 from sathvikbhagavan/sb/docs
docs: clean up tutorials
2 parents bec1cd9 + 2b162c7 commit 51202f6

39 files changed

+484
-479
lines changed

.github/workflows/Documentation.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ jobs:
2020
Pkg.develop(PackageSpec(path=pwd()));
2121
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesAbstractGPs")));
2222
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesFlux")));
23-
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesMOE")));
2423
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesPolyChaos")));
2524
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesRandomForest")));
25+
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesMOE")));
2626
Pkg.develop(PackageSpec(path=joinpath(pwd(), "lib", "SurrogatesSVM")));
2727
Pkg.instantiate()'
2828
- name: Build and deploy

docs/Project.toml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
44
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
55
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
66
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
7+
Surrogates = "6fc51010-71bc-11e9-0e15-a3fcc6593c49"
78
SurrogatesAbstractGPs = "78aa1720-c2af-471b-b307-964fd38f9b5f"
89
SurrogatesFlux = "4f55584b-dac4-4b1c-802a-b7c47b72cb4c"
910
SurrogatesMOE = "778709c9-3595-4497-80d4-d1077d5b9fbf"

docs/make.jl

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cp("./docs/Project.toml", "./docs/src/assets/Project.toml", force = true)
55

66
# Make sure that plots don't throw a bunch of warnings / errors!
77
ENV["GKSwstype"] = "100"
8+
ENV["JULIA_DEBUG"] = "Documenter"
89
using Plots
910

1011
include("pages.jl")

docs/src/BraninFunction.md

+11-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ First of all, we will import these two packages: `Surrogates` and `Plots`.
1212
```@example BraninFunction
1313
using Surrogates
1414
using Plots
15-
default()
1615
```
1716

1817
Now, let's define our objective function:
@@ -40,7 +39,7 @@ n_samples = 80
4039
lower_bound = [-5, 0]
4140
upper_bound = [10, 15]
4241
xys = sample(n_samples, lower_bound, upper_bound, SobolSample())
43-
zs = branin.(xys);
42+
zs = branin.(xys)
4443
x, y = -5.00:10.00, 0.00:15.00
4544
p1 = surface(x, y, (x1, x2) -> branin((x1, x2)))
4645
xs = [xy[1] for xy in xys]
@@ -73,11 +72,11 @@ InverseDistance = InverseDistanceSurrogate(xys, zs, lower_bound, upper_bound)
7372
```
7473

7574
```@example BraninFunction
76-
p1 = surface(x, y, (x, y) -> InverseDistance([x y])) # hide
77-
scatter!(xs, ys, zs, marker_z = zs) # hide
78-
p2 = contour(x, y, (x, y) -> InverseDistance([x y])) # hide
79-
scatter!(xs, ys, marker_z = zs) # hide
80-
plot(p1, p2, title = "Inverse Distance Surrogate") # hide
75+
p1 = surface(x, y, (x, y) -> InverseDistance([x y]))
76+
scatter!(xs, ys, zs, marker_z = zs)
77+
p2 = contour(x, y, (x, y) -> InverseDistance([x y]))
78+
scatter!(xs, ys, marker_z = zs)
79+
plot(p1, p2, title = "Inverse Distance Surrogate")
8180
```
8281

8382
Now, let's talk about `Lobachevsky Surrogate`:
@@ -88,9 +87,9 @@ Lobachevsky = LobachevskySurrogate(
8887
```
8988

9089
```@example BraninFunction
91-
p1 = surface(x, y, (x, y) -> Lobachevsky([x y])) # hide
92-
scatter!(xs, ys, zs, marker_z = zs) # hide
93-
p2 = contour(x, y, (x, y) -> Lobachevsky([x y])) # hide
94-
scatter!(xs, ys, marker_z = zs) # hide
95-
plot(p1, p2, title = "Lobachevsky Surrogate") # hide
90+
p1 = surface(x, y, (x, y) -> Lobachevsky([x y]))
91+
scatter!(xs, ys, zs, marker_z = zs)
92+
p2 = contour(x, y, (x, y) -> Lobachevsky([x y]))
93+
scatter!(xs, ys, marker_z = zs)
94+
plot(p1, p2, title = "Lobachevsky Surrogate")
9695
```

docs/src/ImprovedBraninFunction.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
The Branin Function is commonly used as a test function for metamodelling in computer experiments, especially in the context of optimization.
44

5-
# Modifications for Improved Branin Function:
5+
## Modifications for Improved Branin Function:
66

77
To enhance the Branin function, changes were made to introduce irregularities, variability, and a dynamic aspect to its landscape. Here's an example:
88

@@ -27,7 +27,7 @@ end
2727

2828
This improved function now incorporates irregularities, variability, and a dynamic aspect. These changes aim to make the optimization landscape more challenging and realistic.
2929

30-
# Using the Improved Branin Function:
30+
## Using the Improved Branin Function:
3131

3232
After defining the improved Branin function, you can proceed to test different surrogates and visualize their performance using the updated function. Here's an example of using the improved function with the Radial Basis surrogate:
3333

docs/src/InverseDistance.md

+31-32
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# InverseDistance Surrogate Tutorial
2+
13
The **Inverse Distance Surrogate** is an interpolating method, and in this method, the unknown points are calculated with a weighted average of the sampling points. This model uses the inverse distance between the unknown and training points to predict the unknown point. We do not need to fit this model because the response of an unknown point x is computed with respect to the distance between x and the training points.
24

35
Let's optimize the following function to use Inverse Distance Surrogate:
@@ -9,17 +11,16 @@ First of all, we have to import these two packages: `Surrogates` and `Plots`.
911
```@example Inverse_Distance1D
1012
using Surrogates
1113
using Plots
12-
default()
1314
```
1415

1516
### Sampling
1617

17-
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.
18+
We choose to sample f in 1000 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.
1819

1920
```@example Inverse_Distance1D
2021
f(x) = sin(x) + sin(x)^2 + sin(x)^3
2122
22-
n_samples = 25
23+
n_samples = 100
2324
lower_bound = 0.0
2425
upper_bound = 10.0
2526
x = sample(n_samples, lower_bound, upper_bound, HaltonSample())
@@ -33,8 +34,6 @@ plot!(f, label = "True function", xlims = (lower_bound, upper_bound), legend = :
3334

3435
```@example Inverse_Distance1D
3536
InverseDistance = InverseDistanceSurrogate(x, y, lower_bound, upper_bound)
36-
add_point!(InverseDistance, 5.0, f(5.0))
37-
add_point!(InverseDistance, [5.1, 5.2], [f(5.1), f(5.2)])
3837
prediction = InverseDistance(5.0)
3938
```
4039

@@ -55,7 +54,7 @@ Having built a surrogate, we can now use it to search for minima in our original
5554
To optimize using our surrogate we call `surrogate_optimize` method. We choose to use Stochastic RBF as the optimization technique and again Sobol sampling as the sampling technique.
5655

5756
```@example Inverse_Distance1D
58-
@show surrogate_optimize(
57+
surrogate_optimize(
5958
f, SRBF(), lower_bound, upper_bound, InverseDistance, SobolSample())
6059
scatter(x, y, label = "Sampled points", legend = :top)
6160
plot!(f, label = "True function", xlims = (lower_bound, upper_bound), legend = :top)
@@ -68,9 +67,9 @@ plot!(InverseDistance, label = "Surrogate function",
6867
First of all we will define the `Schaffer` function we are going to build a surrogate for. Notice, how its argument is a vector of numbers, one for each coordinate, and its output is a scalar.
6968

7069
```@example Inverse_DistanceND
71-
using Plots # hide
72-
default(c = :matter, legend = false, xlabel = "x", ylabel = "y") # hide
73-
using Surrogates # hide
70+
using Plots
71+
default(c = :matter, legend = false, xlabel = "x", ylabel = "y")
72+
using Surrogates
7473
7574
function schaffer(x)
7675
x1 = x[1]
@@ -83,10 +82,10 @@ end
8382

8483
### Sampling
8584

86-
Let's define our bounds, this time we are working in two dimensions. In particular we want our first dimension `x` to have bounds `-5, 10`, and `0, 15` for the second dimension. We are taking 60 samples of the space using Sobol Sequences. We then evaluate our function on all the sampling points.
85+
Let's define our bounds, this time we are working in two dimensions. In particular we want our first dimension `x` to have bounds `-5, 10`, and `0, 15` for the second dimension. We are taking 100 samples of the space using Sobol Sequences. We then evaluate our function on all the sampling points.
8786

8887
```@example Inverse_DistanceND
89-
n_samples = 60
88+
n_samples = 100
9089
lower_bound = [-5.0, 0.0]
9190
upper_bound = [10.0, 15.0]
9291
@@ -95,14 +94,14 @@ zs = schaffer.(xys);
9594
```
9695

9796
```@example Inverse_DistanceND
98-
x, y = -5:10, 0:15 # hide
99-
p1 = surface(x, y, (x1, x2) -> schaffer((x1, x2))) # hide
100-
xs = [xy[1] for xy in xys] # hide
101-
ys = [xy[2] for xy in xys] # hide
102-
scatter!(xs, ys, zs) # hide
103-
p2 = contour(x, y, (x1, x2) -> schaffer((x1, x2))) # hide
104-
scatter!(xs, ys) # hide
105-
plot(p1, p2, title = "True function") # hide
97+
x, y = -5:10, 0:15
98+
p1 = surface(x, y, (x1, x2) -> schaffer((x1, x2)))
99+
xs = [xy[1] for xy in xys]
100+
ys = [xy[2] for xy in xys]
101+
scatter!(xs, ys, zs)
102+
p2 = contour(x, y, (x1, x2) -> schaffer((x1, x2)))
103+
scatter!(xs, ys)
104+
plot(p1, p2, title = "True function")
106105
```
107106

108107
### Building a surrogate
@@ -114,11 +113,11 @@ InverseDistance = InverseDistanceSurrogate(xys, zs, lower_bound, upper_bound)
114113
```
115114

116115
```@example Inverse_DistanceND
117-
p1 = surface(x, y, (x, y) -> InverseDistance([x y])) # hide
118-
scatter!(xs, ys, zs, marker_z = zs) # hide
119-
p2 = contour(x, y, (x, y) -> InverseDistance([x y])) # hide
120-
scatter!(xs, ys, marker_z = zs) # hide
121-
plot(p1, p2, title = "Surrogate") # hide
116+
p1 = surface(x, y, (x, y) -> InverseDistance([x y]))
117+
scatter!(xs, ys, zs, marker_z = zs)
118+
p2 = contour(x, y, (x, y) -> InverseDistance([x y]))
119+
scatter!(xs, ys, marker_z = zs)
120+
plot(p1, p2, title = "Surrogate")
122121
```
123122

124123
### Optimizing
@@ -142,12 +141,12 @@ size(xys)
142141
```
143142

144143
```@example Inverse_DistanceND
145-
p1 = surface(x, y, (x, y) -> InverseDistance([x y])) # hide
146-
xs = [xy[1] for xy in xys] # hide
147-
ys = [xy[2] for xy in xys] # hide
148-
zs = schaffer.(xys) # hide
149-
scatter!(xs, ys, zs, marker_z = zs) # hide
150-
p2 = contour(x, y, (x, y) -> InverseDistance([x y])) # hide
151-
scatter!(xs, ys, marker_z = zs) # hide
152-
plot(p1, p2) # hide
144+
p1 = surface(x, y, (x, y) -> InverseDistance([x y]))
145+
xs = [xy[1] for xy in xys]
146+
ys = [xy[2] for xy in xys]
147+
zs = schaffer.(xys)
148+
scatter!(xs, ys, zs, marker_z = zs)
149+
p2 = contour(x, y, (x, y) -> InverseDistance([x y]))
150+
scatter!(xs, ys, marker_z = zs)
151+
plot(p1, p2)
153152
```

docs/src/LinearSurrogate.md

+31-34
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@ First of all we have to import these two packages: `Surrogates` and `Plots`.
99
```@example linear_surrogate1D
1010
using Surrogates
1111
using Plots
12-
default()
1312
```
1413

1514
### Sampling
1615

17-
We choose to sample f in 20 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Sobol sequence, this can be done by passing `SobolSample()` to the `sample` function.
16+
We choose to sample f in 100 points between 0 and 10 using the `sample` function. The sampling points are chosen using a Sobol sequence, this can be done by passing `SobolSample()` to the `sample` function.
1817

1918
```@example linear_surrogate1D
20-
f(x) = sin(x) + log(x)
21-
n_samples = 20
19+
f(x) = 2 * x + 10.0
20+
n_samples = 100
2221
lower_bound = 5.2
2322
upper_bound = 12.5
2423
x = sample(n_samples, lower_bound, upper_bound, SobolSample())
@@ -35,8 +34,6 @@ We can simply calculate `linear_surrogate` for any value.
3534

3635
```@example linear_surrogate1D
3736
my_linear_surr_1D = LinearSurrogate(x, y, lower_bound, upper_bound)
38-
add_point!(my_linear_surr_1D, 4.0, 7.2)
39-
add_point!(my_linear_surr_1D, [5.0, 6.0], [8.3, 9.7])
4037
val = my_linear_surr_1D(5.0)
4138
```
4239

@@ -56,7 +53,7 @@ Having built a surrogate, we can now use it to search for minima in our original
5653
To optimize using our surrogate we call `surrogate_optimize` method. We choose to use Stochastic RBF as the optimization technique and again Sobol sampling as the sampling technique.
5754

5855
```@example linear_surrogate1D
59-
@show surrogate_optimize(
56+
surrogate_optimize(
6057
f, SRBF(), lower_bound, upper_bound, my_linear_surr_1D, SobolSample())
6158
scatter(x, y, label = "Sampled points")
6259
plot!(f, label = "True function", xlims = (lower_bound, upper_bound))
@@ -68,9 +65,9 @@ plot!(my_linear_surr_1D, label = "Surrogate function", xlims = (lower_bound, upp
6865
First of all we will define the `Egg Holder` function we are going to build a surrogate for. Notice, one how its argument is a vector of numbers, one for each coordinate, and its output is a scalar.
6966

7067
```@example linear_surrogateND
71-
using Plots # hide
72-
default(c = :matter, legend = false, xlabel = "x", ylabel = "y") # hide
73-
using Surrogates # hide
68+
using Plots
69+
default(c = :matter, legend = false, xlabel = "x", ylabel = "y")
70+
using Surrogates
7471
7572
function egg(x)
7673
x1 = x[1]
@@ -83,26 +80,26 @@ end
8380

8481
### Sampling
8582

86-
Let's define our bounds, this time we are working in two dimensions. In particular we want our first dimension `x` to have bounds `-10, 5`, and `0, 15` for the second dimension. We are taking 50 samples of the space using Sobol Sequences. We then evaluate our function on all of the sampling points.
83+
Let's define our bounds, this time we are working in two dimensions. In particular we want our first dimension `x` to have bounds `-10, 5`, and `0, 15` for the second dimension. We are taking 100 samples of the space using Sobol Sequences. We then evaluate our function on all of the sampling points.
8784

8885
```@example linear_surrogateND
89-
n_samples = 50
86+
n_samples = 100
9087
lower_bound = [-10.0, 0.0]
9188
upper_bound = [5.0, 15.0]
9289
9390
xys = sample(n_samples, lower_bound, upper_bound, SobolSample())
94-
zs = egg.(xys);
91+
zs = egg.(xys)
9592
```
9693

9794
```@example linear_surrogateND
98-
x, y = -10:5, 0:15 # hide
99-
p1 = surface(x, y, (x1, x2) -> egg((x1, x2))) # hide
100-
xs = [xy[1] for xy in xys] # hide
101-
ys = [xy[2] for xy in xys] # hide
102-
scatter!(xs, ys, zs) # hide
103-
p2 = contour(x, y, (x1, x2) -> egg((x1, x2))) # hide
104-
scatter!(xs, ys) # hide
105-
plot(p1, p2, title = "True function") # hide
95+
x, y = -10:5, 0:15
96+
p1 = surface(x, y, (x1, x2) -> egg((x1, x2)))
97+
xs = [xy[1] for xy in xys]
98+
ys = [xy[2] for xy in xys]
99+
scatter!(xs, ys, zs)
100+
p2 = contour(x, y, (x1, x2) -> egg((x1, x2)))
101+
scatter!(xs, ys)
102+
plot(p1, p2, title = "True function")
106103
```
107104

108105
### Building a surrogate
@@ -114,11 +111,11 @@ my_linear_ND = LinearSurrogate(xys, zs, lower_bound, upper_bound)
114111
```
115112

116113
```@example linear_surrogateND
117-
p1 = surface(x, y, (x, y) -> my_linear_ND([x y])) # hide
118-
scatter!(xs, ys, zs, marker_z = zs) # hide
119-
p2 = contour(x, y, (x, y) -> my_linear_ND([x y])) # hide
120-
scatter!(xs, ys, marker_z = zs) # hide
121-
plot(p1, p2, title = "Surrogate") # hide
114+
p1 = surface(x, y, (x, y) -> my_linear_ND([x y]))
115+
scatter!(xs, ys, zs, marker_z = zs)
116+
p2 = contour(x, y, (x, y) -> my_linear_ND([x y]))
117+
scatter!(xs, ys, marker_z = zs)
118+
plot(p1, p2, title = "Surrogate")
122119
```
123120

124121
### Optimizing
@@ -142,12 +139,12 @@ size(xys)
142139
```
143140

144141
```@example linear_surrogateND
145-
p1 = surface(x, y, (x, y) -> my_linear_ND([x y])) # hide
146-
xs = [xy[1] for xy in xys] # hide
147-
ys = [xy[2] for xy in xys] # hide
148-
zs = egg.(xys) # hide
149-
scatter!(xs, ys, zs, marker_z = zs) # hide
150-
p2 = contour(x, y, (x, y) -> my_linear_ND([x y])) # hide
151-
scatter!(xs, ys, marker_z = zs) # hide
152-
plot(p1, p2) # hide
142+
p1 = surface(x, y, (x, y) -> my_linear_ND([x y]))
143+
xs = [xy[1] for xy in xys]
144+
ys = [xy[2] for xy in xys]
145+
zs = egg.(xys)
146+
scatter!(xs, ys, zs, marker_z = zs)
147+
p2 = contour(x, y, (x, y) -> my_linear_ND([x y]))
148+
scatter!(xs, ys, marker_z = zs)
149+
plot(p1, p2)
153150
```

docs/src/Salustowicz.md

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ Let's import these two packages `Surrogates` and `Plots`:
1212
```@example salustowicz1D
1313
using Surrogates
1414
using Plots
15-
default()
1615
```
1716

1817
Now, let's define our objective function:

0 commit comments

Comments
 (0)