import numpy as np
from math import inf
from spotPython.fun.objectivefunctions import analytical
from spotPython.spot import spot
from scipy.optimize import shgo
from scipy.optimize import direct
from scipy.optimize import differential_evolution
import matplotlib.pyplot as plt
import pylab
from numpy import append, ndarray, multiply, isinf, linspace, meshgrid, ravel
from numpy import array
2 Multi-dimensional Functions
This notebook illustrates how high-dimensional functions can be analyzed.
2.1 Example: Spot
and the 3-dim Sphere Function
2.1.1 The Objective Function: 3-dim Sphere
The
spotPython
package provides several classes of objective functions.We will use an analytical objective function, i.e., a function that can be described by a (closed) formula: \[f(x) = \sum_i^n x_i^2 \]
Here we will use \(n=3\).
= analytical().fun_sphere fun
The size of the
lower
bound vector determines the problem dimension.Here we will use
np.array([-1, -1, -1])
, i.e., a three-dim function.We will use three different
theta
values (one for each dimension), i.e., we setsurrogate_control={"n_theta": 3}
.
= spot.Spot(fun=fun,
spot_3 = -1.0*np.ones(3),
lower = np.ones(3),
upper =["Pressure", "Temp", "Lambda"],
var_name=True,
show_progress={"n_theta": 3})
surrogate_control
spot_3.run()
spotPython tuning: 0.03443399805488846 [#######---] 73.33%
spotPython tuning: 0.03134895672225177 [########--] 80.00%
spotPython tuning: 0.0009630555620661592 [#########-] 86.67%
spotPython tuning: 8.567364874637509e-05 [#########-] 93.33%
spotPython tuning: 6.0300780324366926e-05 [##########] 100.00% Done...
<spotPython.spot.spot.Spot at 0x11103b550>
2.1.2 Results
spot_3.print_results()
min y: 6.0300780324366926e-05
Pressure: 0.00514742089151478
Temp: 0.001954003740617489
Lambda: 0.005476012040857559
[['Pressure', 0.00514742089151478],
['Temp', 0.001954003740617489],
['Lambda', 0.005476012040857559]]
spot_3.plot_progress()
2.1.3 A Contour Plot
- We can select two dimensions, say \(i=0\) and \(j=1\), and generate a contour plot as follows.
- Note: We have specified identical
min_z
andmax_z
values to generate comparable plots!
- Note: We have specified identical
=0, j=1, min_z=0, max_z=2.25) spot_3.plot_contour(i
- In a similar manner, we can plot dimension \(i=0\) and \(j=2\):
=0, j=2, min_z=0, max_z=2.25) spot_3.plot_contour(i
- The final combination is \(i=1\) and \(j=2\):
=1, j=2, min_z=0, max_z=2.25) spot_3.plot_contour(i
- The three plots look very similar, because the
fun_sphere
is symmetric. - This can also be seen from the variable importance:
spot_3.print_importance()
Pressure: 100.0
Temp: 99.69922253450551
Lambda: 93.68147774373058
[['Pressure', 100.0],
['Temp', 99.69922253450551],
['Lambda', 93.68147774373058]]
2.2 Conclusion
Based on this quick analysis, we can conclude that all three dimensions are equally important (as expected, because the analytical function is known).
2.3 Exercises
- Important:
- Results from these exercises should be added to this document, i.e., you should submit an updated version of this notebook.
- Please combine your results using this notebook.
- Only one notebook from each group!
- Presentation is based on this notebook. No addtional slides are required!
- spotPython version
0.16.11
(or greater) is required
2.3.1 The Three Dimensional fun_cubed
- The input dimension is
3
. The search range is \(-1 \leq x \leq 1\) for all dimensions. - Generate contour plots
- Calculate the variable importance.
- Discuss the variable importance:
- Are all variables equally important?
- If not:
- Which is the most important variable?
- Which is the least important variable?
2.3.2 The Ten Dimensional fun_wing_wt
- The input dimension is
10
. The search range is \(0 \leq x \leq 1\) for all dimensions. - Calculate the variable importance.
- Discuss the variable importance:
- Are all variables equally important?
- If not:
- Which is the most important variable?
- Which is the least important variable?
- Generate contour plots for the three most important variables. Do they confirm your selection?
2.3.3 The Three Dimensional fun_runge
- The input dimension is
3
. The search range is \(-5 \leq x \leq 5\) for all dimensions. - Generate contour plots
- Calculate the variable importance.
- Discuss the variable importance:
- Are all variables equally important?
- If not:
- Which is the most important variable?
- Which is the least important variable?
2.3.4 The Three Dimensional fun_linear
- The input dimension is
3
. The search range is \(-5 \leq x \leq 5\) for all dimensions. - Generate contour plots
- Calculate the variable importance.
- Discuss the variable importance:
- Are all variables equally important?
- If not:
- Which is the most important variable?
- Which is the least important variable?