Skip to content

Commit 7b5cc32

Browse files
branin test
1 parent ffd00a3 commit 7b5cc32

4 files changed

Lines changed: 320 additions & 81 deletions

File tree

notebooks/00_spotPython_tests.ipynb

Lines changed: 258 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,6 +1269,264 @@
12691269
"spot_1.run()"
12701270
]
12711271
},
1272+
{
1273+
"cell_type": "code",
1274+
"execution_count": null,
1275+
"metadata": {},
1276+
"outputs": [],
1277+
"source": [
1278+
"import numpy as np\n",
1279+
"def squared_euclidean_distance(X_0, X, theta):\n",
1280+
" return np.sum(theta*(X_0 - X)**2)"
1281+
]
1282+
},
1283+
{
1284+
"cell_type": "code",
1285+
"execution_count": 1,
1286+
"metadata": {},
1287+
"outputs": [],
1288+
"source": [
1289+
"import numpy as np\n",
1290+
"from numpy import array, zeros, power, ones, exp, multiply, eye, linspace, mat, spacing, sqrt, arange, append, ravel\n",
1291+
"from numpy.linalg import cholesky, solve\n",
1292+
"from numpy.random import multivariate_normal\n",
1293+
"def build_Psi(X, theta):\n",
1294+
" n = X.shape[0]\n",
1295+
" k = X.shape[1]\n",
1296+
" D = zeros((k, n, n))\n",
1297+
" for l in range(k):\n",
1298+
" for i in range(n):\n",
1299+
" for j in range(i, n):\n",
1300+
" D[l, i, j] = theta[l]*(X[i,l] - X[j,l])**2\n",
1301+
" D = sum(D)\n",
1302+
" D = D + D.T\n",
1303+
" return exp(-D) "
1304+
]
1305+
},
1306+
{
1307+
"cell_type": "code",
1308+
"execution_count": 15,
1309+
"metadata": {},
1310+
"outputs": [
1311+
{
1312+
"name": "stdout",
1313+
"output_type": "stream",
1314+
"text": [
1315+
"(3, 2)\n"
1316+
]
1317+
},
1318+
{
1319+
"data": {
1320+
"text/plain": [
1321+
"array([[1., 0.],\n",
1322+
" [1., 1.],\n",
1323+
" [0., 1.]])"
1324+
]
1325+
},
1326+
"execution_count": 15,
1327+
"metadata": {},
1328+
"output_type": "execute_result"
1329+
}
1330+
],
1331+
"source": [
1332+
"theta = np.array([1.0, 1.0])\n",
1333+
"X = np.array([[1.0, 0.0], [1.0, 1.0], [0.0, 1.0]])\n",
1334+
"print(X.shape)\n",
1335+
"X"
1336+
]
1337+
},
1338+
{
1339+
"cell_type": "code",
1340+
"execution_count": 14,
1341+
"metadata": {},
1342+
"outputs": [
1343+
{
1344+
"data": {
1345+
"text/plain": [
1346+
"array([[1. , 0.36787944, 0.13533528],\n",
1347+
" [0.36787944, 1. , 0.36787944],\n",
1348+
" [0.13533528, 0.36787944, 1. ]])"
1349+
]
1350+
},
1351+
"execution_count": 14,
1352+
"metadata": {},
1353+
"output_type": "execute_result"
1354+
}
1355+
],
1356+
"source": [
1357+
"build_Psi(X, theta)"
1358+
]
1359+
},
1360+
{
1361+
"cell_type": "code",
1362+
"execution_count": 18,
1363+
"metadata": {},
1364+
"outputs": [
1365+
{
1366+
"data": {
1367+
"text/plain": [
1368+
"array([55.60211264, 65.60211264, 45.60211264])"
1369+
]
1370+
},
1371+
"execution_count": 18,
1372+
"metadata": {},
1373+
"output_type": "execute_result"
1374+
}
1375+
],
1376+
"source": [
1377+
"from spotPython.fun.objectivefunctions import analytical\n",
1378+
"import numpy as np\n",
1379+
"X = np.array([[0, 0, 0], [0, 0, 1], [0, 0, 2]])\n",
1380+
"fun = analytical()\n",
1381+
"fun.fun_branin_factor(X)"
1382+
]
1383+
},
1384+
{
1385+
"cell_type": "code",
1386+
"execution_count": 22,
1387+
"metadata": {},
1388+
"outputs": [
1389+
{
1390+
"data": {
1391+
"text/plain": [
1392+
"array([55.60211264, 0.39788736, 0.39788736, 0.39788736])"
1393+
]
1394+
},
1395+
"execution_count": 22,
1396+
"metadata": {},
1397+
"output_type": "execute_result"
1398+
}
1399+
],
1400+
"source": [
1401+
"import numpy as np\n",
1402+
"pi = np.pi\n",
1403+
"X = np.array([[0,0], [-pi, 12.275], [pi, 2.275], [9.42478, 2.475]])\n",
1404+
"fun = analytical()\n",
1405+
"fun.fun_branin(X)"
1406+
]
1407+
},
1408+
{
1409+
"cell_type": "code",
1410+
"execution_count": 33,
1411+
"metadata": {},
1412+
"outputs": [],
1413+
"source": [
1414+
"from spotPython.fun.objectivefunctions import analytical\n",
1415+
"import numpy as np\n",
1416+
"pi = np.pi\n",
1417+
"X_0 = np.array([[0, 0]])\n",
1418+
"X_1 = np.array([[-pi, 12.275], [pi, 2.275], [9.42478, 2.475]])\n",
1419+
"X_2 = np.array([[0,0,0], [0,0,1], [0,0,2]])\n",
1420+
"fun = analytical()\n",
1421+
"y_0 = fun.fun_branin(X_0)\n",
1422+
"y_1 = fun.fun_branin(X_1)\n",
1423+
"y_2 = fun.fun_branin_factor(X_2)"
1424+
]
1425+
},
1426+
{
1427+
"cell_type": "code",
1428+
"execution_count": 37,
1429+
"metadata": {},
1430+
"outputs": [
1431+
{
1432+
"data": {
1433+
"text/plain": [
1434+
"True"
1435+
]
1436+
},
1437+
"execution_count": 37,
1438+
"metadata": {},
1439+
"output_type": "execute_result"
1440+
}
1441+
],
1442+
"source": [
1443+
"round(y_1[0], 2) == round(y_1[1],2)\n"
1444+
]
1445+
},
1446+
{
1447+
"cell_type": "code",
1448+
"execution_count": 38,
1449+
"metadata": {},
1450+
"outputs": [
1451+
{
1452+
"data": {
1453+
"text/plain": [
1454+
"True"
1455+
]
1456+
},
1457+
"execution_count": 38,
1458+
"metadata": {},
1459+
"output_type": "execute_result"
1460+
}
1461+
],
1462+
"source": [
1463+
"\n",
1464+
"round(y_1[0], 2) == round(y_1[2],2)\n"
1465+
]
1466+
},
1467+
{
1468+
"cell_type": "code",
1469+
"execution_count": 45,
1470+
"metadata": {},
1471+
"outputs": [
1472+
{
1473+
"data": {
1474+
"text/plain": [
1475+
"array([ True])"
1476+
]
1477+
},
1478+
"execution_count": 45,
1479+
"metadata": {},
1480+
"output_type": "execute_result"
1481+
}
1482+
],
1483+
"source": [
1484+
"\n",
1485+
"y_2[0] == y_0\n"
1486+
]
1487+
},
1488+
{
1489+
"cell_type": "code",
1490+
"execution_count": 40,
1491+
"metadata": {},
1492+
"outputs": [
1493+
{
1494+
"data": {
1495+
"text/plain": [
1496+
"array([ True])"
1497+
]
1498+
},
1499+
"execution_count": 40,
1500+
"metadata": {},
1501+
"output_type": "execute_result"
1502+
}
1503+
],
1504+
"source": [
1505+
"\n",
1506+
"y_2[1] == y_0 + 10\n"
1507+
]
1508+
},
1509+
{
1510+
"cell_type": "code",
1511+
"execution_count": 41,
1512+
"metadata": {},
1513+
"outputs": [
1514+
{
1515+
"data": {
1516+
"text/plain": [
1517+
"array([ True])"
1518+
]
1519+
},
1520+
"execution_count": 41,
1521+
"metadata": {},
1522+
"output_type": "execute_result"
1523+
}
1524+
],
1525+
"source": [
1526+
"\n",
1527+
"y_2[2] == y_0 - 10\n"
1528+
]
1529+
},
12721530
{
12731531
"cell_type": "code",
12741532
"execution_count": null,

pyproject.toml

Lines changed: 1 addition & 1 deletion
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.7.3"
10+
version = "0.7.5"
1111
authors = [
1212
{ name="T. Bartz-Beielstein", email="tbb@bartzundbartz.de" }
1313
]

0 commit comments

Comments
 (0)