Skip to content

Commit 0eb37cc

Browse files
0.18.14
1 parent c607929 commit 0eb37cc

4 files changed

Lines changed: 114 additions & 59 deletions

File tree

RELEASE_NOTES.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
spotpython 0.18.14:
2+
3+
- "river>=0.22.0" and "numpy>=2.1.0" updated in the dependencies
4+
5+
- objectivefunctions.py:
6+
doc updated
7+
8+
19
spotpackage 0.18.13:
210

311
- listgenerator.py:

notebooks/00_spotPython_tests.ipynb

Lines changed: 58 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5489,7 +5489,7 @@
54895489
" - layer_sizes: A dictionary with layer names as keys and their sizes as entries in NumPy array format.\n",
54905490
"\n",
54915491
" Examples:\n",
5492-
" >>> # Example usage (as described in the original function's docstring)\n",
5492+
" # Example usage (as described in the original function's docstring)\n",
54935493
" \"\"\"\n",
54945494
" weights = {}\n",
54955495
" index = []\n",
@@ -5706,7 +5706,7 @@
57065706
" - layer_sizes: A dictionary with layer names as keys and their sizes as entries in NumPy array format.\n",
57075707
"\n",
57085708
" Examples:\n",
5709-
" >>> # Example usage to compute gradients\n",
5709+
" # Example usage to compute gradients\n",
57105710
" \"\"\"\n",
57115711
" net.eval()\n",
57125712
" dataset = fun_control[\"data_set\"]\n",
@@ -5870,7 +5870,7 @@
58705870
" tuple: A tuple containing the activations, mean activations, and layer sizes for each layer.\n",
58715871
"\n",
58725872
" Examples:\n",
5873-
" >>> from spotpython.plot.xai import get_activations\n",
5873+
" from spotpython.plot.xai import get_activations\n",
58745874
" activations, mean_activations, layer_sizes = get_activations(net, fun_control)\n",
58755875
" \"\"\"\n",
58765876
" activations = {}\n",
@@ -7040,6 +7040,61 @@
70407040
"trainer.test(net_light_base, test_loader)"
70417041
]
70427042
},
7043+
{
7044+
"cell_type": "markdown",
7045+
"metadata": {},
7046+
"source": [
7047+
"# Test Objective Functions"
7048+
]
7049+
},
7050+
{
7051+
"cell_type": "code",
7052+
"execution_count": 2,
7053+
"metadata": {},
7054+
"outputs": [
7055+
{
7056+
"data": {
7057+
"text/plain": [
7058+
"array([ 36., 405., -3.])"
7059+
]
7060+
},
7061+
"execution_count": 2,
7062+
"metadata": {},
7063+
"output_type": "execute_result"
7064+
}
7065+
],
7066+
"source": [
7067+
"from spotpython.fun.objectivefunctions import analytical\n",
7068+
"import numpy as np\n",
7069+
"X = np.array([[1, 2, 3], [4, 5, 6], [-1, -1, -1]])\n",
7070+
"fun = analytical()\n",
7071+
"fun.fun_cubed(X)\n"
7072+
]
7073+
},
7074+
{
7075+
"cell_type": "code",
7076+
"execution_count": 5,
7077+
"metadata": {},
7078+
"outputs": [
7079+
{
7080+
"data": {
7081+
"text/plain": [
7082+
"array([158.28245046, 409.33182691])"
7083+
]
7084+
},
7085+
"execution_count": 5,
7086+
"metadata": {},
7087+
"output_type": "execute_result"
7088+
}
7089+
],
7090+
"source": [
7091+
"from spotpython.fun.objectivefunctions import analytical\n",
7092+
"import numpy as np\n",
7093+
"X = np.array([np.zeros(10), np.ones(10)])\n",
7094+
"fun = analytical()\n",
7095+
"fun.fun_wingwt(X)"
7096+
]
7097+
},
70437098
{
70447099
"cell_type": "code",
70457100
"execution_count": null,

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
77

88
[project]
99
name = "spotpython"
10-
version = "0.18.13"
10+
version = "0.18.14"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]
@@ -36,14 +36,14 @@ dependencies = [
3636
"mkdocs-gen-files>=0.5.0",
3737
"mkdocs-literate-nav>=0.6.1",
3838
"mkdocs-section-index>=0.3.9",
39-
"numpy",
39+
"numpy>=2.1.0",
4040
"nbformat",
4141
"pandas",
4242
"plotly",
4343
"PyQt6",
4444
"python-markdown-math",
4545
"pytorch-lightning>=1.4",
46-
"river>=0.21.0",
46+
"river>=0.22.0",
4747
"scikit-learn",
4848
"scipy",
4949
"spotriver>=0.4.1",

src/spotpython/fun/objectivefunctions.py

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def fun_sphere(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.nd
203203
return y
204204

205205
def fun_cubed(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.ndarray:
206-
"""Cubed function.
206+
"""Cubed function. Implements the function f(x) = sum((x_i - offset)^3).
207207
208208
Args:
209209
X (array):
@@ -217,10 +217,10 @@ def fun_cubed(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.nda
217217
Examples:
218218
>>> from spotpython.fun.objectivefunctions import analytical
219219
>>> import numpy as np
220-
>>> X = np.array([[1, 2, 3], [4, 5, 6]])
220+
>>> X = np.array([[1, 2, 3], [4, 5, 6], [-1, -1, -1]])
221221
>>> fun = analytical()
222222
>>> fun.fun_cubed(X)
223-
array([ 0., 27.])
223+
array([ 36., 405., -3.])
224224
"""
225225

226226
if fun_control is None:
@@ -455,36 +455,6 @@ def fun_sin_cos(self, X, fun_control=None):
455455
else:
456456
return y
457457

458-
# def fun_forrester_2(self, X):
459-
# """
460-
# Function used by [Forr08a, p.83].
461-
# f(x) = (6x- 2)^2 sin(12x-4) for x in [0,1].
462-
# Starts with three sample points at x=0, x=0.5, and x=1.
463-
464-
# Args:
465-
# X (flooat): input values (1-dim)
466-
467-
# Returns:
468-
# float: function value
469-
# """
470-
# try:
471-
# X.shape[1]
472-
# except ValueError:
473-
# X = np.array(X)
474-
475-
# X = np.atleast_2d(X)
476-
# # y = X[:, 1]
477-
# y = (6.0 * X - 2) ** 2 * np.sin(12 * X - 4)
478-
# if self.sigma != 0:
479-
# noise_y = np.array([], dtype=float)
480-
# for i in y:
481-
# noise_y = np.append(
482-
# noise_y, i + np.random.normal(loc=0, scale=self.sigma, size=1)
483-
# )
484-
# return noise_y
485-
# else:
486-
# return y
487-
488458
def fun_runge(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.ndarray:
489459
"""Runge function. Formula: f(x) = 1/ (1 + sum(x_i) - offset)^2. Dim: k >= 1.
490460
Interval: -5 <= x <= 5
@@ -522,39 +492,61 @@ def fun_runge(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.nda
522492
return y
523493

524494
def fun_wingwt(self, X: np.ndarray, fun_control: Optional[Dict] = None) -> np.ndarray:
525-
r"""Wing weight function. Example from Forrester et al. to understand the weight
526-
of an unpainted light aircraft wing as a function of nine design and operational parameters:
527-
$W=0.036 S_W^{0.758} Wfw^{0.0035} ( A / (\cos^2 \Lambda))^{0.6} q^{0.006} \lambda^{0.04} ( (100 Rtc)/(\cos
528-
\Lambda) ))^{-0.3} (Nz Wdg)^{0.49}$
495+
r"""Wing weight function.
496+
Calculate the weight of an unpainted light aircraft wing based on design and operational parameters.
497+
This function implements the wing weight model from Forrester et al., which aims to predict
498+
the wing weight \( W \) using the following formula:
499+
500+
\[
501+
W = 0.036 \times S_W^{0.758} \times W_{fw}^{0.0035} \times \left( \frac{A}{\cos^2 \Lambda} \right)^{0.6} \times q^{0.006} \times \lambda^{0.04} \times \left( \frac{100 \times R_{tc}}{\cos \Lambda} \right)^{-0.3} \times (N_z \times W_{dg})^{0.49} + S_W \times W_p
502+
\]
503+
504+
where:
505+
506+
- \( S_W \): Wing area \((\text{ft}^2)\)
507+
- \( W_{fw} \): Weight of fuel in the wing (lb)
508+
- \( A \): Aspect ratio
509+
- \( \Lambda \): Quarter-chord sweep (degrees)
510+
- \( q \): Dynamic pressure at cruise \((\text{lb/ft}^2)\)
511+
- \( \lambda \): Taper ratio
512+
- \( R_{tc} \): Aerofoil thickness to chord ratio
513+
- \( N_z \): Ultimate load factor
514+
- \( W_{dg} \): Flight design gross weight (lb)
515+
- \( W_p \): Paint weight \((\text{lb/ft}^2)\)
516+
517+
Parameter Overview:
529518
530519
| Symbol | Parameter | Baseline | Minimum | Maximum |
531520
|-----------|----------------------------------------|----------|---------|---------|
532-
| $S_W$ | Wing area ($ft^2$) | 174 | 150 | 200 |
533-
| $W_{fw}$ | Weight of fuel in wing (lb) | 252 | 220 | 300 |
534-
| $A$ | Aspect ratio | 7.52 | 6 | 10 |
535-
| $\Lambda$ | Quarter-chord sweep (deg) | 0 | -10 | 10 |
536-
| $q$ | Dynamic pressure at cruise ($lb/ft^2$) | 34 | 16 | 45 |
537-
| $\lambda$ | Taper ratio | 0.672 | 0.5 | 1 |
538-
| $R_{tc}$ | Aerofoil thickness to chord ratio | 0.12 | 0.08 | 0.18 |
539-
| $N_z$ | Ultimate load factor | 3.8 | 2.5 | 6 |
540-
| $W_{dg}$ | Flight design gross weight (lb) | 2000 | 1700 | 2500 |
541-
| $W_p$ | paint weight (lb/ft^2) | 0.064 | 0.025 | 0.08 |
521+
| \( S_W \) | Wing area \((\text{ft}^2)\) | 174 | 150 | 200 |
522+
| \( W_{fw} \) | Weight of fuel in wing (lb) | 252 | 220 | 300 |
523+
| \( A \) | Aspect ratio | 7.52 | 6 | 10 |
524+
| \( \Lambda \) | Quarter-chord sweep (deg) | 0 | -10 | 10 |
525+
| \( q \) | Dynamic pressure at cruise \((\text{lb/ft}^2)\) | 34 | 16 | 45 |
526+
| \( \lambda \) | Taper ratio | 0.672 | 0.5 | 1 |
527+
| \( R_{tc} \) | Aerofoil thickness to chord ratio | 0.12 | 0.08 | 0.18 |
528+
| \( N_z \) | Ultimate load factor | 3.8 | 2.5 | 6 |
529+
| \( W_{dg} \) | Flight design gross weight (lb) | 2000 | 1700 | 2500 |
530+
| \( W_p \) | Paint weight \((\text{lb/ft}^2)\) | 0.064 | 0.025 | 0.08 |
542531
543532
Args:
544-
X (array): input
545-
fun_control (dict): dict with entries `sigma` (noise level) and `seed` (random seed).
533+
X (np.ndarray):
534+
A 2D numpy array where each row contains 10 parameters for which the wing weight will be calculated.
535+
fun_control (Optional[Dict]):
536+
A dictionary with keys `sigma` (noise level) and `seed` (random seed)
537+
for incorporating randomness if required. Default is `None`.
546538
547539
Returns:
548-
np.ndarray: A 1D numpy array with shape (n,) containing the calculated values.
540+
np.ndarray:
541+
A 1D numpy array with shape (n,) containing the calculated wing weight values.
549542
550543
Examples:
551544
>>> from spotpython.fun.objectivefunctions import analytical
552545
>>> import numpy as np
553-
>>> X = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 10, 11, 12]])
546+
>>> X = np.array([np.zeros(10), np.ones(10)])
554547
>>> fun = analytical()
555548
>>> fun.fun_wingwt(X)
556-
array([0.0625 , 0.015625 , 0.00390625])
557-
549+
array([158.28245046, 409.33182691])
558550
"""
559551
if fun_control is None:
560552
fun_control = self.fun_control

0 commit comments

Comments
 (0)