Merge remote-tracking branch 'origin/main'

# Conflicts:
#	Hansen_ES_CMA.py
#	dashboard.py
This commit is contained in:
2026-01-12 15:27:06 +01:00
2 changed files with 479 additions and 167 deletions

View File

@@ -1,5 +1,5 @@
import numpy as np
from typing import Callable
def felli(x):
N = x.shape[0]
@@ -9,16 +9,24 @@ def felli(x):
return float(np.sum((1e6 ** exponents) * (x ** 2)))
def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
bestEver = np.inf, noImproveGen = 0, absTolImprove = 1e-10, maxNoImproveGen = 100, sigmaImprove = 1e-12):
#Initialization
def escma(func, *, N=10, xmean=None, sigma=0.5, stopfitness=1e-10, stopeval=None,
func_args=(), func_kwargs=None, seed=None):
# User defined input parameters
# N = 10
# xmean = np.random.rand(N)
# sigma = 0.5
# stopfitness = 1e-10
# stopeval = int(1e3 * N**2)
if func_kwargs is None:
func_kwargs = {}
if seed is not None:
np.random.seed(seed)
# Initialization (aus Parametern statt hart verdrahtet)
if xmean is None:
xmean = np.random.rand(N)
else:
xmean = np.asarray(xmean, dtype=float)
N = xmean.shape[0]
if stopeval is None:
stopeval = int(1e3 * N**2)
# Strategy parameter setting: Selection
lambda_ = 4 + int(np.floor(3 * np.log(N)))
@@ -47,7 +55,7 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
eigeneval = 0
chiN = np.sqrt(N) * (1 - 1/(4*N) + 1/(21 * N**2))
#Generation Loop
# Generation Loop
counteval = 0
arx = np.zeros((N, lambda_))
arz = np.zeros((N, lambda_))
@@ -64,7 +72,7 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
for k in range(lambda_):
arz[:, k] = np.random.randn(N)
arx[:, k] = xmean + sigma * (B @ D @ arz[:, k])
arfitness[k] = fitnessfct(arx[:, k])
arfitness[k] = float(func(arx[:, k], *func_args, **func_kwargs)) # <-- allgemein
counteval += 1
# Sort by fitness and compute weighted mean into xmean
@@ -145,6 +153,6 @@ def escma(fitnessfct: Callable, N, xmean, sigma, stopfitness, stopeval,
if __name__ == "__main__":
xmin = escma()
xmin = escma(felli, N=10) # <-- Zielfunktion wird übergeben
print("Bestes gefundenes x:", xmin)
print("f(xmin) =", felli(xmin))