function.forr08a
function.forr08a
Functions
| Name | Description |
|---|---|
| aerofoilcd | Computes the drag coefficient (cd) of an aerofoil based on the shape parameter X. |
| branin | Branin’s test function that takes a 2D input vector x in the range [0, 1] for each dimension |
| onevar | One-variable test function that takes a scalar or 1D array input x in the range [0, 1] |
aerofoilcd
function.forr08a.aerofoilcd(X)Computes the drag coefficient (cd) of an aerofoil based on the shape parameter X.
This function reads the drag coefficient data from the “cd_data.csv” file and uses the input X (rounded to the nearest 0.01) to return the corresponding drag coefficients.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| X | np.ndarray | A 1D NumPy array of values in the range [0, 1] representing the shape parameters. | required |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: A 1D NumPy array of drag coefficients (cd) corresponding to the input X. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If any value in X is outside the range [0, 1]. |
Examples
>>> from spotpython.surrogate.functions.forr08a import aerofoilcd
>>> X = np.array([0.5, 0.75])
>>> aerofoilcd(X)
array([0.029975, 0.033375])branin
function.forr08a.branin(x)Branin’s test function that takes a 2D input vector x in the range [0, 1] for each dimension and returns the corresponding scalar function value. The function is vectorized to handle multiple inputs.
The function is defined as
f(x) = a * (X2 - b * X1^2 + c * X1 - d)^2 + e * (1 - ff) * cos(X1) + e + 5 * x1
where: X1 = 15 * x1 - 5 X2 = 15 * x2
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | np.ndarray | A 2D NumPy array of shape (n_samples, 2) where each row is a 2D input vector. | required |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: The calculated function values for the input x. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If x does not have exactly 2 columns or if any value in x is outside the range [0, 1]. |
Examples
>>> import numpy as np
>>> from spotpython.surrogate.functions.forr08a import branin
>>> # Single input
>>> print(branin(np.array([[0.5, 0.5]])))
[26.63]
>>> # Multiple inputs
>>> x = np.array([[0.0, 0.0], [0.25, 0.25], [0.5, 0.5], [0.75, 0.75], [1.0, 1.0]])
>>> print(branin(x))
[308.1291, 34.0028, 26.63, 126.3879, 150.8722]onevar
function.forr08a.onevar(x)One-variable test function that takes a scalar or 1D array input x in the range [0, 1] and returns the corresponding function values. The function is vectorized to handle multiple inputs.
The function is defined as
f(x) = ((6x - 2)^2) * np.sin((6x - 2) * 2)
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | np.ndarray | A scalar or 1D NumPy array of values in the range [0, 1]. | required |
Returns
| Name | Type | Description |
|---|---|---|
| np.ndarray | np.ndarray: The calculated function values for the input x. |
Raises
| Name | Type | Description |
|---|---|---|
| ValueError | If any value in x is outside the range [0, 1]. |
Examples
>>> import numpy as np
>>> from spotpython.surrogate.functions.forr08a import onevar
>>> # Single input
>>> print(onevar(np.array([0.5])))
[0.9093]
>>> # Multiple inputs
>>> x = np.array([0.0, 0.25, 0.5, 0.75, 1.0])
>>> print(onevar(x))
[3.0272, -0.2104, 0.9093, -5.9933, 15.8297]