diff --git a/ea/Ub4/a12.py b/ea/Ub4/a12.py new file mode 100644 index 0000000..f53af5a --- /dev/null +++ b/ea/Ub4/a12.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +import numpy as np +import matplotlib.pyplot as plt +import copy as cp + +def binary (b, u=31, l=-32, length=6): + s=0 + for i in np.arange(1,length+1) : + s+=b[length-i]*2**(i-1) + return l+(u-l)/(2**length-1)*s + +def f1 (x): + return x**2 + +def matchScheme (scheme): + ind=[] + ind.append([]) + if(scheme[0]==0) or (scheme[0]==1): + ind[0]=[scheme[i]] + c=1 + else: + ind[0]=[0] + ind.append([1]) + c=2 + for i in np.arange(1,len(scheme)): + if (scheme[i] == 0) or (scheme[i] == 1): + for j in np.arange(0,c): + ind[j].append(scheme[i]) + else : + ind2=cp.deepcopy(ind) + for j in np.arange(0,c): + ind.append(ind2[j]) + for j in np.arange(0,c): + ind[j].append(0) + for j in np.arange(c,2*c): + ind[j].append(1) + c=2*c + return ind + +x=np.arange(-32,32) +plt.scatter(x,f1(x), label='x^2') +#plt.grid(True) + +H3=['*',1,1,'*','*','*'] +H3scheme=list(map(binary,matchScheme(H3))) +H4=['*','*','*',0,0,'*'] +H4scheme=list(map(binary,matchScheme(H4))) + +plt.vlines(H3scheme,list([0]*len(H3scheme)), list(map(f1,H3scheme)), linestyles='dashed', label='H3') +plt.vlines(H4scheme,list([0]*len(H4scheme)), list(map(f1,H4scheme)), linestyles='dotted', label='H4') +plt.legend(bbox_to_anchor=(0.6,0.8)) + +plt.show() diff --git a/ea/Ub4/ea4.pdf b/ea/Ub4/ea4.pdf index 051080c..aedf9bb 100644 --- a/ea/Ub4/ea4.pdf +++ b/ea/Ub4/ea4.pdf Binary files differ diff --git a/ea/Ub4/ea4.tex b/ea/Ub4/ea4.tex index 51030cd..94d7300 100644 --- a/ea/Ub4/ea4.tex +++ b/ea/Ub4/ea4.tex @@ -7,6 +7,8 @@ \usepackage{hyperref} %Links \usepackage{ifthen} %ifthenelse \usepackage{enumerate} +\usepackage{listings} +\lstset{language=Python} \usepackage{algpseudocode} %Pseudocode \usepackage{dsfont} % schöne Zahlenräumezeichen @@ -22,9 +24,10 @@ \newcounter{aufgabe} \def\tand{&} + \newcommand{\makeTableLine}[2][0]{% - \setcounter{aufgabe}{1}% - \whiledo{\value{aufgabe} < #1}% + \setcounter{aufgabe}{10}%TODO update + \whiledo{\value{aufgabe} < 13}%TODO update {% #2\tand\stepcounter{aufgabe}% } @@ -65,6 +68,7 @@ %counts the exercisenumber \newcounter{n} +\setcounter{n}{9} %TODO update %Kommando für Aufgaben %\Aufgabe{AufgTitel}{Punktezahl} @@ -76,7 +80,7 @@ %\header{BlattNr}{Tutor}{Abgabedatum}{Vorlesungsname}{Namen}{Semester}{Anzahl Aufgaben} \header{4}{}{2015-19-05}{Evolutionäre Algorithmen}{ \textit{Jan-Peter Hohloch}\\ \textit{Maximus Mutschler} - }{SS 15}{3} + }{SS 15}{3}%TODO update \vspace{0.5cm} \Aufgabe{Roulette-Rad-Selektion}{6}\\ \begin{enumerate}[(a)] \item Binomialverteilung da Ziehen mit Zurücklegen\\ @@ -91,7 +95,7 @@ \sigma^2 = n\cdot(E(X^2)-E^2(X)) = |P| \cdot p_i \cdot (1-p_i) $ \\ - \item + \item \begin{itemize} \item $p_1= 0.01\\ |P|=60\\ @@ -115,7 +119,7 @@ $ \end{itemize} \end{enumerate} - \Aufgabe{Schemate}{7} + \Aufgabe{Schemata}{7} $ f_1(x) = (x-8)^2\\ O(H)=2\\ @@ -138,7 +142,7 @@ x10x&4,5,12,13&10.5\\ x11x&5,7,14,15&22.5\\ \end{tabular} - + Beste Fitness: $10xx$ mit 3.5\\ \item Graycode:\\ \begin{tabular}{|c |c| c|} @@ -157,8 +161,8 @@ x11x&4,5,10,11&9.5\\ \end{tabular} \\ Beste Fitness: $x10x$ mit 1.5\\ - \end{itemize} - \Aufgabe{3}{7} + \end{itemize}\pagebreak + \Aufgabe{Schematheorem}{7} \begin{enumerate}[(a)] \item Fitnessfunktion definiert als Anzahl der Nullen.\\ $ @@ -174,7 +178,7 @@ \delta_1=1\\ \rightarrow m(H_1,t+1) \geq 6.2222$\\ - Die Anzahl der Exemplare des Schemas H1 vergrößert sich um mindestens 24.44\% + Die Anzahl der Exemplare des Schemas H1 vergrößert sich um mindestens 24.44\% \item $H_2\\ m(H_2,t)= 1\\ f(H_2)= 2\\ @@ -182,25 +186,74 @@ \delta_2=4\\ \rightarrow m(H_2,t+1) \geq 0.2593$\\ - Die Anzahl der Exemplare des Schemas H2 verringert sich um höchstens 74.07\% + Die Anzahl der Exemplare des Schemas H2 verringert sich um höchstens 74.07\% \end{itemize} - - - - - \item Matlabed verbugged die Legende... bekomms nicht hin. + + \item Code:\\ + \begin{lstlisting} +#!/usr/bin/python +import numpy as np +import matplotlib.pyplot as plt +import copy as cp + +def binary (b, u=31, l=-32, length=6): + s=0 + for i in np.arange(1,length+1) : + s+=b[length-i]*2**(i-1) + return l+(u-l)/(2**length-1)*s + +def f1 (x): + return x**2 + +def matchScheme (scheme): + ind=[] + ind.append([]) + if(scheme[0]==0) or (scheme[0]==1): + ind[0]=[scheme[i]] + c=1 + else: + ind[0]=[0] + ind.append([1]) + c=2 + for i in np.arange(1,len(scheme)): + if (scheme[i] == 0) or (scheme[i] == 1): + for j in np.arange(0,c): + ind[j].append(scheme[i]) + else : + ind2=cp.deepcopy(ind) + for j in np.arange(0,c): + ind.append(ind2[j]) + for j in np.arange(0,c): + ind[j].append(0) + for j in np.arange(c,2*c): + ind[j].append(1) + c=2*c + return ind + +x=np.arange(-32,32) +plt.scatter(x,f1(x), label='x^2') +#plt.grid(True) + +H3=['*',1,1,'*','*','*'] +H3scheme=list(map(binary,matchScheme(H3))) +H4=['*','*','*',0,0,'*'] +H4scheme=list(map(binary,matchScheme(H4))) + +plt.vlines(H3scheme,list([0]*len(H3scheme)), list(map(f1,H3scheme)), + linestyles='dashed', label='H3') +plt.vlines(H4scheme,list([0]*len(H4scheme)), list(map(f1,H4scheme)), + linestyles='dotted', label='H4') +plt.legend(bbox_to_anchor=(0.6,0.8)) + +plt.show() + \end{lstlisting} \begin{figure}[!htb] \centering - \includegraphics[width= 0.7\textwidth]{A3Plot.png} + \includegraphics[width= 0.9\textwidth]{figure_1.png} \caption{\label{fig:1}Zielfunktion sowie die Lösungsräume von H3 und H4} \end{figure} - + \end{enumerate} - - - - - - + \end{document} diff --git a/ea/Ub4/figure_1.png b/ea/Ub4/figure_1.png new file mode 100644 index 0000000..813f971 --- /dev/null +++ b/ea/Ub4/figure_1.png Binary files differ