diff --git a/ea/ubA/a28.py b/ea/ubA/a28.py index b22edb6..d1f9572 100644 --- a/ea/ubA/a28.py +++ b/ea/ubA/a28.py @@ -34,10 +34,11 @@ stats=np.zeros((6,4,1000)) j=0 +runs=1000 # decrease for reasonable computationtime for zw in np.array([0.15,0.2,0.25,0.3,0.5,0.6]): - for i in np.arange(0,100): + for i in np.arange(0,runs): stats[j]=stats[j]+np.transpose(ES(2,1,corridor,zw=zw,lb=0,ub=0)) - stats[j]=stats[j]/100 + stats[j]=stats[j]/runs plt.plot(stats[j][0],stats[j][1],"rx") plt.xlabel("t") plt.ylabel("sigma") diff --git a/ea/ubA/eaA.pdf b/ea/ubA/eaA.pdf index 5c8f0fa..b7bd87f 100644 --- a/ea/ubA/eaA.pdf +++ b/ea/ubA/eaA.pdf Binary files differ diff --git a/ea/ubA/eaA.tex b/ea/ubA/eaA.tex index fb43b20..9f1a906 100644 --- a/ea/ubA/eaA.tex +++ b/ea/ubA/eaA.tex @@ -9,7 +9,7 @@ \usepackage{enumerate} \usepackage{listings} \lstset{language=Python} - +\usepackage{pgffor} \usepackage{algpseudocode} %Pseudocode \usepackage{dsfont} % schöne Zahlenräumezeichen \usepackage{amssymb, amsthm} %noch stärker erweiterte Mathe-Zeichen @@ -94,10 +94,81 @@ \Leftrightarrow \sin\left(\pi\cdot w_e\right)=\frac{s}{2r}\\ \Leftrightarrow r=\frac{s}{2\sin\left(w_e\pi\right)}\\ \Rightarrow r=\frac{3cm}{2\sin\left(0.2\pi\right)}\approx 2.552cm=\sigma_{opt}$ - \end{enumerate} + \end{enumerate}\pagebreak\\ \Aufgabe{1/5-Erfolgsregel (Praxis)}{11}\\ - %TODO plots - \Aufgabe{Rekombinations in ES}{4} + \foreach \x in {0.15,0.2,0.25,0.3,0.5,0.6}{ + \includegraphics[width=0.33\textwidth]{figures/sigma\x .png} + \includegraphics[width=0.33\textwidth]{figures/we\x .png} + \includegraphics[width=0.33\textwidth]{figures/fitness\x .png}\\ + }\\ + \begin{lstlisting} +import numpy as np +import matplotlib.pyplot as plt + +def ES(n,sigma,eval,term=lambda P,t:t>=100000, + kappa=0.82,zw=0.2,fit=lambda P:P[0],lb=-10,ub=10): + t=0 + P=np.random.uniform(lb, ub, n) + succ=0 + stats=[] + while not term(P,t): + Pm=P+np.random.normal(0,sigma,n) + + if eval(P,Pm,t): + P=Pm + succ=succ+1 + t=t+1 + if (t % 100) == 0: + we=succ/100 + stats.append([t,sigma,we,fit(P)]) + if we < zw: + sigma=sigma*kappa + if we > zw: + sigma=sigma/kappa + succ=0 + return stats + +def minimizeAbs(P,Pm,t): + return np.sum(np.abs(P))>np.sum(np.abs(Pm)) + +def corridor(P,Pm,t,b=np.array([10,13,1,6,18,20,4,10,13,2])): + if (P[1]-Pm[1]) <= b[t//10000]: + return Pm[0]>P[0] + else: + return 0 + +stats=np.zeros((6,4,1000)) +j=0 +for zw in np.array([0.15,0.2,0.25,0.3,0.5,0.6]): + for i in np.arange(0,1000): + stats[j]=stats[j] + +np.transpose(ES(2,1,corridor,zw=zw,lb=0,ub=0)) + stats[j]=stats[j]/1000 + plt.plot(stats[j][0],stats[j][1],"rx") + plt.xlabel("t") + plt.ylabel("sigma") + plt.title("sigma over time, zw="+str(zw)) + #plt.axis((0,100000,0,1e10)) + plt.savefig("sigma"+str(zw)+".png") + plt.close() + plt.plot(stats[j][0],stats[j][2],"rx") + plt.xlabel("t") + plt.ylabel("we") + plt.title("we over time, zw="+str(zw)) + plt.axis((0,100000,0,0.55)) + plt.savefig("we"+str(zw)+".png") + plt.close() + plt.plot(stats[j][0],stats[j][3],"rx") + plt.xlabel("t") + plt.ylabel("fitness") + plt.title("fitness over time, zw="+str(zw)) + plt.axis((0,100000,0,1e5)) + plt.savefig("fitness"+str(zw)+".png") + plt.close() + j=j+1 +np.save("stats.npy",stats) +\end{lstlisting} + \Aufgabe{Rekombination in ES}{4} \begin{enumerate}[(a)] \item $a_1'=(0.23,-0.92,-0.23,-0.85,0.21)$ \item $a_2'=((0.25,1.18,0.36,0.53,0.14)+(1.18,-0.88,-0.23,-0.85,0.14))/2\\=(0.715,0.15,0.065,-0.16,0.14)$ diff --git a/ea/ubA/figures/fitness0.15.png b/ea/ubA/figures/fitness0.15.png index 5ee2587..2d99eca 100644 --- a/ea/ubA/figures/fitness0.15.png +++ b/ea/ubA/figures/fitness0.15.png Binary files differ diff --git a/ea/ubA/figures/fitness0.2.png b/ea/ubA/figures/fitness0.2.png index fea7b52..8de0541 100644 --- a/ea/ubA/figures/fitness0.2.png +++ b/ea/ubA/figures/fitness0.2.png Binary files differ diff --git a/ea/ubA/figures/fitness0.25.png b/ea/ubA/figures/fitness0.25.png index 559fa7b..0616c2f 100644 --- a/ea/ubA/figures/fitness0.25.png +++ b/ea/ubA/figures/fitness0.25.png Binary files differ diff --git a/ea/ubA/figures/fitness0.3.png b/ea/ubA/figures/fitness0.3.png index bfd322d..8d48961 100644 --- a/ea/ubA/figures/fitness0.3.png +++ b/ea/ubA/figures/fitness0.3.png Binary files differ diff --git a/ea/ubA/figures/fitness0.5.png b/ea/ubA/figures/fitness0.5.png index 92ee177..2b02218 100644 --- a/ea/ubA/figures/fitness0.5.png +++ b/ea/ubA/figures/fitness0.5.png Binary files differ diff --git a/ea/ubA/figures/sigma0.15.png b/ea/ubA/figures/sigma0.15.png index 70d6364..9b300e4 100644 --- a/ea/ubA/figures/sigma0.15.png +++ b/ea/ubA/figures/sigma0.15.png Binary files differ diff --git a/ea/ubA/figures/sigma0.2.png b/ea/ubA/figures/sigma0.2.png index 3171689..1d4c7ef 100644 --- a/ea/ubA/figures/sigma0.2.png +++ b/ea/ubA/figures/sigma0.2.png Binary files differ diff --git a/ea/ubA/figures/sigma0.25.png b/ea/ubA/figures/sigma0.25.png index b8123c9..5fc0fbf 100644 --- a/ea/ubA/figures/sigma0.25.png +++ b/ea/ubA/figures/sigma0.25.png Binary files differ diff --git a/ea/ubA/figures/sigma0.3.png b/ea/ubA/figures/sigma0.3.png index b31e4a9..1fcf18a 100644 --- a/ea/ubA/figures/sigma0.3.png +++ b/ea/ubA/figures/sigma0.3.png Binary files differ diff --git a/ea/ubA/figures/sigma0.5.png b/ea/ubA/figures/sigma0.5.png index a05b2de..5e6dd8c 100644 --- a/ea/ubA/figures/sigma0.5.png +++ b/ea/ubA/figures/sigma0.5.png Binary files differ diff --git a/ea/ubA/figures/we0.15.png b/ea/ubA/figures/we0.15.png index d185df1..37f2380 100644 --- a/ea/ubA/figures/we0.15.png +++ b/ea/ubA/figures/we0.15.png Binary files differ diff --git a/ea/ubA/figures/we0.2.png b/ea/ubA/figures/we0.2.png index c4e095f..e3a082d 100644 --- a/ea/ubA/figures/we0.2.png +++ b/ea/ubA/figures/we0.2.png Binary files differ diff --git a/ea/ubA/figures/we0.25.png b/ea/ubA/figures/we0.25.png index 7f640cc..1ace9f3 100644 --- a/ea/ubA/figures/we0.25.png +++ b/ea/ubA/figures/we0.25.png Binary files differ diff --git a/ea/ubA/figures/we0.3.png b/ea/ubA/figures/we0.3.png index 3759585..98a70e7 100644 --- a/ea/ubA/figures/we0.3.png +++ b/ea/ubA/figures/we0.3.png Binary files differ diff --git a/ea/ubA/figures/we0.5.png b/ea/ubA/figures/we0.5.png index 5443f37..210b45d 100644 --- a/ea/ubA/figures/we0.5.png +++ b/ea/ubA/figures/we0.5.png Binary files differ