Source

evolve-proj / ausarbeitung.html

Full commit
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.9.1: http://docutils.sourceforge.net/" />
<title></title>
<style type="text/css">

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 7434 2012-05-11 21:06:27Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.

See http://docutils.sf.net/docs/howto/html-stylesheets.html for how to
customize this style sheet.
*/

/* used to remove borders from tables and images */
.borderless, table.borderless td, table.borderless th {
  border: 0 }

table.borderless td, table.borderless th {
  /* Override padding for "table.docutils td" with "! important".
     The right padding separates the table cells. */
  padding: 0 0.5em 0 0 ! important }

.first {
  /* Override more specific margin styles with "! important". */
  margin-top: 0 ! important }

.last, .with-subtitle {
  margin-bottom: 0 ! important }

.hidden {
  display: none }

a.toc-backref {
  text-decoration: none ;
  color: black }

blockquote.epigraph {
  margin: 2em 5em ; }

dl.docutils dd {
  margin-bottom: 0.5em }

object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
  overflow: hidden;
}

/* Uncomment (and remove this text!) to get bold-faced definition list terms
dl.docutils dt {
  font-weight: bold }
*/

div.abstract {
  margin: 2em 5em }

div.abstract p.topic-title {
  font-weight: bold ;
  text-align: center }

div.admonition, div.attention, div.caution, div.danger, div.error,
div.hint, div.important, div.note, div.tip, div.warning {
  margin: 2em ;
  border: medium outset ;
  padding: 1em }

div.admonition p.admonition-title, div.hint p.admonition-title,
div.important p.admonition-title, div.note p.admonition-title,
div.tip p.admonition-title {
  font-weight: bold ;
  font-family: sans-serif }

div.attention p.admonition-title, div.caution p.admonition-title,
div.danger p.admonition-title, div.error p.admonition-title,
div.warning p.admonition-title {
  color: red ;
  font-weight: bold ;
  font-family: sans-serif }

/* Uncomment (and remove this text!) to get reduced vertical space in
   compound paragraphs.
div.compound .compound-first, div.compound .compound-middle {
  margin-bottom: 0.5em }

div.compound .compound-last, div.compound .compound-middle {
  margin-top: 0.5em }
*/

div.dedication {
  margin: 2em 5em ;
  text-align: center ;
  font-style: italic }

div.dedication p.topic-title {
  font-weight: bold ;
  font-style: normal }

div.figure {
  margin-left: 2em ;
  margin-right: 2em }

div.footer, div.header {
  clear: both;
  font-size: smaller }

div.line-block {
  display: block ;
  margin-top: 1em ;
  margin-bottom: 1em }

div.line-block div.line-block {
  margin-top: 0 ;
  margin-bottom: 0 ;
  margin-left: 1.5em }

div.sidebar {
  margin: 0 0 0.5em 1em ;
  border: medium outset ;
  padding: 1em ;
  background-color: #ffffee ;
  width: 40% ;
  float: right ;
  clear: right }

div.sidebar p.rubric {
  font-family: sans-serif ;
  font-size: medium }

div.system-messages {
  margin: 5em }

div.system-messages h1 {
  color: red }

div.system-message {
  border: medium outset ;
  padding: 1em }

div.system-message p.system-message-title {
  color: red ;
  font-weight: bold }

div.topic {
  margin: 2em }

h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
  margin-top: 0.4em }

h1.title {
  text-align: center }

h2.subtitle {
  text-align: center }

hr.docutils {
  width: 75% }

img.align-left, .figure.align-left, object.align-left {
  clear: left ;
  float: left ;
  margin-right: 1em }

img.align-right, .figure.align-right, object.align-right {
  clear: right ;
  float: right ;
  margin-left: 1em }

img.align-center, .figure.align-center, object.align-center {
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.align-left {
  text-align: left }

.align-center {
  clear: both ;
  text-align: center }

.align-right {
  text-align: right }

/* reset inner alignment in figures */
div.align-right {
  text-align: inherit }

/* div.align-center * { */
/*   text-align: left } */

ol.simple, ul.simple {
  margin-bottom: 1em }

ol.arabic {
  list-style: decimal }

ol.loweralpha {
  list-style: lower-alpha }

ol.upperalpha {
  list-style: upper-alpha }

ol.lowerroman {
  list-style: lower-roman }

ol.upperroman {
  list-style: upper-roman }

p.attribution {
  text-align: right ;
  margin-left: 50% }

p.caption {
  font-style: italic }

p.credits {
  font-style: italic ;
  font-size: smaller }

p.label {
  white-space: nowrap }

p.rubric {
  font-weight: bold ;
  font-size: larger ;
  color: maroon ;
  text-align: center }

p.sidebar-title {
  font-family: sans-serif ;
  font-weight: bold ;
  font-size: larger }

p.sidebar-subtitle {
  font-family: sans-serif ;
  font-weight: bold }

p.topic-title {
  font-weight: bold }

pre.address {
  margin-bottom: 0 ;
  margin-top: 0 ;
  font: inherit }

pre.literal-block, pre.doctest-block, pre.math, pre.code {
  margin-left: 2em ;
  margin-right: 2em }

pre.code .ln { /* line numbers */
  color: grey;
}

.code {
  background-color: #eeeeee
}

span.classifier {
  font-family: sans-serif ;
  font-style: oblique }

span.classifier-delimiter {
  font-family: sans-serif ;
  font-weight: bold }

span.interpreted {
  font-family: sans-serif }

span.option {
  white-space: nowrap }

span.pre {
  white-space: pre }

span.problematic {
  color: red }

span.section-subtitle {
  /* font-size relative to parent (h1..h6 element) */
  font-size: 80% }

table.citation {
  border-left: solid 1px gray;
  margin-left: 1px }

table.docinfo {
  margin: 2em 4em }

table.docutils {
  margin-top: 0.5em ;
  margin-bottom: 0.5em }

table.footnote {
  border-left: solid 1px black;
  margin-left: 1px }

table.docutils td, table.docutils th,
table.docinfo td, table.docinfo th {
  padding-left: 0.5em ;
  padding-right: 0.5em ;
  vertical-align: top }

table.docutils th.field-name, table.docinfo th.docinfo-name {
  font-weight: bold ;
  text-align: left ;
  white-space: nowrap ;
  padding-left: 0 }

h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
  font-size: 100% }

ul.auto-toc {
  list-style-type: none }

</style>
<style type="text/css">

.highlight .hll { background-color: #ffffcc }
.highlight  { background: #ffffff; }
.highlight .c { color: #008800; font-style: italic } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #000080; font-weight: bold } /* Keyword */
.highlight .cm { color: #008800; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #008080 } /* Comment.Preproc */
.highlight .c1 { color: #008800; font-style: italic } /* Comment.Single */
.highlight .cs { color: #008800; font-weight: bold } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #999999 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #aaaaaa } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #000080; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #000080; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #000080; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #000080; font-weight: bold } /* Keyword.Pseudo */
.highlight .kr { color: #000080; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #000080; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000FF } /* Literal.Number */
.highlight .s { color: #0000FF } /* Literal.String */
.highlight .na { color: #FF0000 } /* Name.Attribute */
.highlight .nt { color: #000080; font-weight: bold } /* Name.Tag */
.highlight .ow { font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mf { color: #0000FF } /* Literal.Number.Float */
.highlight .mh { color: #0000FF } /* Literal.Number.Hex */
.highlight .mi { color: #0000FF } /* Literal.Number.Integer */
.highlight .mo { color: #0000FF } /* Literal.Number.Oct */
.highlight .sb { color: #0000FF } /* Literal.String.Backtick */
.highlight .sc { color: #800080 } /* Literal.String.Char */
.highlight .sd { color: #0000FF } /* Literal.String.Doc */
.highlight .s2 { color: #0000FF } /* Literal.String.Double */
.highlight .se { color: #0000FF } /* Literal.String.Escape */
.highlight .sh { color: #0000FF } /* Literal.String.Heredoc */
.highlight .si { color: #0000FF } /* Literal.String.Interpol */
.highlight .sx { color: #0000FF } /* Literal.String.Other */
.highlight .sr { color: #0000FF } /* Literal.String.Regex */
.highlight .s1 { color: #0000FF } /* Literal.String.Single */
.highlight .ss { color: #0000FF } /* Literal.String.Symbol */
.highlight .il { color: #0000FF } /* Literal.Number.Integer.Long */
</style>
</head>
<body>
<div class="document">
<div class="section" id="betrachtung-genetischer-programmierung">
<h1>Betrachtung Genetischer Programmierung</h1>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">Author:</th><td class="field-body">Ronny Pfannschmidt</td>
</tr>
<tr class="field-even field"><th class="field-name">Matr Nr:</th><td class="field-body">250154</td>
</tr>
</tbody>
</table>
<div class="section" id="grundlagen">
<h2>Grundlagen</h2>
<div class="section" id="begriffe">
<h3>Begriffe</h3>
<dl class="docutils">
<dt>Genetische Algorithmen</dt>
<dd>Klasse von Algorithmen,
welche die Prinzipien der Evolution Anwenden
um Problemlöser zu Finden</dd>
<dt>Genetische Programmierung</dt>
<dd>Klasse von Genetischen Algorithmen,
welche anstelle von Merkmals Vektoren Programme oder Funktionen
als Elemente einer Population haben</dd>
</dl>
<p>Allen Genetischen Algorithmen liegen liegen die Komponenten der Evolution
zu Grunde.</p>
<ol class="arabic simple">
<li>Es gibt eine Population</li>
<li>Es gibt Replikation/Fortpflanzung mit Mutation</li>
<li>Es gibt Selektion (in der Natur - Überlebend bis Fortpflanzung/Replikation)</li>
</ol>
</div>
<div class="section" id="eigenschaften-des-algorithmus">
<h3>Eigenschaften des Algorithmus</h3>
<ul class="simple">
<li>parallele Suche in einer Population von möglichen Lösungen,
sodass immer mehrere potentielle Lösungen gefunden werden</li>
<li>benötigen kaum Problem wissen,
insbesondere keine Gradienten Information, können also auch bei
diskontinuierlichen Problemen angewendet werden</li>
<li>gehören zur Klasse der stochastischen Such verfahren
und ermöglichen damit auch die Behandlung von Problemen,
die mit traditionellen Optimierung Methoden nicht mehr handhabbar sind.</li>
<li>Evolutionäre Algorithmen bieten im Allgemeinen keine Garantie,
das globale Optimum in vernünftiger Zeit zu finden.</li>
<li>Großer Nachteil der EAs ist der oft sehr große Rechenzeit bedarf</li>
</ul>
</div>
</div>
<div class="section" id="ein-einfaches-beispiel">
<h2>Ein einfaches Beispiel</h2>
<p>Zu Demonstration zwecken soll mittels eines Genetischen Programms die
Funktion <cite>f(a, b)=sqrt(a*a + b*b)</cite> angenährt werden.</p>
<p>Dazu stehen die folgenden Funktionsbausteine zur Verfügung</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">class</span> <span class="nc">FlushFile</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Write-only flushing wrapper for file-type objects.&quot;&quot;&quot;</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">f</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">f</span> <span class="o">=</span> <span class="n">f</span>
    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">x</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">f</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">f</span><span class="o">.</span><span class="n">flush</span><span class="p">()</span>

<span class="c"># Replace stdout with an automatically flushing version</span>
<span class="n">sys</span><span class="o">.</span><span class="n">stdout</span> <span class="o">=</span> <span class="n">FlushFile</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">__stdout__</span><span class="p">)</span>


<span class="k">def</span> <span class="nf">gp_add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span> <span class="k">return</span> <span class="n">a</span><span class="o">+</span><span class="n">b</span>
<span class="k">def</span> <span class="nf">gp_sub</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span> <span class="k">return</span> <span class="n">a</span><span class="o">-</span><span class="n">b</span>
<span class="k">def</span> <span class="nf">gp_mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">):</span> <span class="k">return</span> <span class="n">a</span><span class="o">*</span><span class="n">b</span>
<span class="k">def</span> <span class="nf">gp_sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">):</span>   <span class="k">return</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">a</span><span class="p">))</span>

<span class="n">functions</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;add&#39;</span><span class="p">:</span> <span class="n">gp_add</span><span class="p">,</span>
    <span class="s">&#39;sub&#39;</span><span class="p">:</span> <span class="n">gp_sub</span><span class="p">,</span>
    <span class="s">&#39;mul&#39;</span><span class="p">:</span> <span class="n">gp_mul</span><span class="p">,</span>
    <span class="s">&#39;sqrt&#39;</span><span class="p">:</span> <span class="n">gp_sqrt</span><span class="p">,</span>
<span class="p">}</span>


<span class="n">stack_functions</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;add&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">+</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()),</span>
    <span class="s">&#39;sub&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">-</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()),</span>
    <span class="s">&#39;mul&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="o">*</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()),</span>
    <span class="s">&#39;sqrt&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span><span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">(</span><span class="nb">abs</span><span class="p">(</span><span class="n">stack</span><span class="o">.</span><span class="n">pop</span><span class="p">()))),</span>
<span class="p">}</span>

<span class="n">stack_terminas</span> <span class="o">=</span> <span class="p">{</span>
    <span class="s">&#39;a&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span> <span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">terminals</span><span class="p">[</span><span class="s">&#39;a&#39;</span><span class="p">]),</span>
    <span class="s">&#39;b&#39;</span><span class="p">:</span> <span class="k">lambda</span> <span class="n">stack</span><span class="p">,</span> <span class="n">terminals</span><span class="p">:</span> <span class="n">stack</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">terminals</span><span class="p">[</span><span class="s">&#39;b&#39;</span><span class="p">]),</span>
<span class="p">}</span>
</pre></div>
</div>
<p>Den Hauptteil des Programmes stellt dabei</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">main_run</span><span class="p">(</span><span class="n">eval_func</span><span class="p">,</span> <span class="n">options</span><span class="p">):</span>
    <span class="n">genome</span> <span class="o">=</span> <span class="n">GTree</span><span class="o">.</span><span class="n">GTreeGP</span><span class="p">()</span>
    <span class="n">genome</span><span class="o">.</span><span class="n">setParams</span><span class="p">(</span><span class="n">max_depth</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s">&quot;ramped&quot;</span><span class="p">)</span>
    <span class="n">genome</span><span class="o">.</span><span class="n">evaluator</span><span class="o">.</span><span class="n">set</span><span class="p">(</span><span class="n">eval_func</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
    <span class="n">genome</span><span class="o">.</span><span class="n">evaluator</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">eval_height</span><span class="p">,</span> <span class="n">options</span><span class="o">.</span><span class="n">height_weight</span><span class="p">)</span>

    <span class="n">ga</span> <span class="o">=</span> <span class="n">GSimpleGA</span><span class="o">.</span><span class="n">GSimpleGA</span><span class="p">(</span><span class="n">genome</span><span class="p">)</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setParams</span><span class="p">(</span><span class="n">gp_terminals</span><span class="o">=</span><span class="p">[</span><span class="s">&#39;a&#39;</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">],</span>
                 <span class="n">gp_function_set</span><span class="o">=</span><span class="p">{</span>
                     <span class="s">&#39;add&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
                     <span class="s">&#39;sub&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
                     <span class="s">&#39;mul&#39;</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
                     <span class="s">&#39;sqrt&#39;</span><span class="p">:</span> <span class="mi">1</span><span class="p">,</span>
                 <span class="p">})</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setMinimax</span><span class="p">(</span><span class="n">Consts</span><span class="o">.</span><span class="n">minimaxType</span><span class="p">[</span><span class="s">&quot;minimize&quot;</span><span class="p">])</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setGenerations</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">generations</span><span class="p">)</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setMutationRate</span><span class="p">(</span><span class="mf">0.08</span><span class="p">)</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setCrossoverRate</span><span class="p">(</span><span class="mf">1.0</span><span class="p">)</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">setPopulationSize</span><span class="p">(</span><span class="n">options</span><span class="o">.</span><span class="n">population</span><span class="p">)</span>
    <span class="n">ga</span><span class="o">.</span><span class="n">evolve</span><span class="p">(</span><span class="n">freq_stats</span><span class="o">=</span><span class="mi">20</span><span class="p">)</span>

    <span class="k">print</span> <span class="n">ga</span><span class="o">.</span><span class="n">bestIndividual</span><span class="p">()</span><span class="o">.</span><span class="n">getPreOrderExpression</span><span class="p">()</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">main</span><span class="p">():</span>
    <span class="kn">import</span> <span class="nn">argparse</span>
    <span class="n">parser</span> <span class="o">=</span> <span class="n">argparse</span><span class="o">.</span><span class="n">ArgumentParser</span><span class="p">()</span>

    <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;command&#39;</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--generations&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">500</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--population&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">int</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">1500</span><span class="p">)</span>
    <span class="n">parser</span><span class="o">.</span><span class="n">add_argument</span><span class="p">(</span><span class="s">&#39;--height-weight&#39;</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="nb">float</span><span class="p">,</span> <span class="n">default</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>

    <span class="n">options</span> <span class="o">=</span> <span class="n">parser</span><span class="o">.</span><span class="n">parse_args</span><span class="p">()</span>
    <span class="n">eval_func</span> <span class="o">=</span> <span class="nb">globals</span><span class="p">()[</span><span class="s">&#39;eval_&#39;</span> <span class="o">+</span> <span class="n">options</span><span class="o">.</span><span class="n">command</span><span class="p">]</span>
    <span class="n">main_run</span><span class="p">(</span><span class="n">eval_func</span><span class="p">,</span> <span class="n">options</span><span class="p">)</span>
</pre></div>
</div>
<p>Als Betrachtungs-grundlage werden 3 Arten
der Evaluierung gegenüber gestellt.</p>
<p><strong>code generator basierte Evaluation</strong></p>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">eval_code</span><span class="p">(</span><span class="n">chromosome</span><span class="p">):</span>
    <span class="n">error_accum</span> <span class="o">=</span> <span class="n">Util</span><span class="o">.</span><span class="n">ErrorAccumulator</span><span class="p">()</span>
    <span class="n">code_comp</span> <span class="o">=</span> <span class="n">chromosome</span><span class="o">.</span><span class="n">getCompiledCode</span><span class="p">()</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">chromosome</span><span class="o">.</span><span class="n">getRoot</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
            <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="c"># The eval will execute a pre-compiled syntax tree</span>
            <span class="c"># as a Python expression, and will automatically use</span>
            <span class="c"># the &quot;a&quot; and &quot;b&quot; variables (the terminals defined)</span>
            <span class="n">evaluated</span>     <span class="o">=</span> <span class="nb">eval</span><span class="p">(</span><span class="n">code_comp</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;a&#39;</span><span class="p">:</span><span class="n">a</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">:</span><span class="n">b</span><span class="p">},</span> <span class="n">functions</span><span class="p">)</span>
            <span class="n">target</span>        <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">a</span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">b</span><span class="o">*</span><span class="n">b</span><span class="p">))</span>
            <span class="n">error_accum</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">evaluated</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">error_accum</span><span class="o">.</span><span class="n">getRMSE</span><span class="p">()</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>visitor basierte Evaluation</strong></p>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">visit_node</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">terminals</span><span class="p">,</span> <span class="n">functions</span><span class="p">):</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
        <span class="k">return</span> <span class="n">terminals</span><span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">node_data</span><span class="p">]</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">func</span> <span class="o">=</span> <span class="n">functions</span><span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">node_data</span><span class="p">]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="n">visit_node</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">terminals</span><span class="p">,</span> <span class="n">functions</span><span class="p">))</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="n">visit_node</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">terminals</span><span class="p">,</span> <span class="n">functions</span><span class="p">),</span>
                        <span class="n">visit_node</span><span class="p">(</span><span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">terminals</span><span class="p">,</span> <span class="n">functions</span><span class="p">))</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">eval_visit</span><span class="p">(</span><span class="n">chromosome</span><span class="p">):</span>
    <span class="n">error_accum</span> <span class="o">=</span> <span class="n">Util</span><span class="o">.</span><span class="n">ErrorAccumulator</span><span class="p">()</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">chromosome</span><span class="o">.</span><span class="n">getRoot</span><span class="p">()</span>
    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
            <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="n">evaluated</span>     <span class="o">=</span> <span class="n">visit_node</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;a&#39;</span><span class="p">:</span><span class="n">a</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">:</span><span class="n">b</span><span class="p">},</span> <span class="n">functions</span><span class="p">)</span>
            <span class="n">target</span>        <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">a</span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">b</span><span class="o">*</span><span class="n">b</span><span class="p">))</span>
            <span class="n">error_accum</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">evaluated</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">error_accum</span><span class="o">.</span><span class="n">getRMSE</span><span class="p">()</span>
</pre></div>
</div>
</div></blockquote>
<p><strong>operator list basierte Evaluation</strong></p>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">nodeops</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="n">functions</span><span class="p">):</span>
    <span class="n">res</span> <span class="o">=</span> <span class="p">[]</span>
    <span class="n">_nodeops</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">functions</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">res</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">_nodeops</span><span class="p">(</span><span class="n">ops</span><span class="p">,</span> <span class="n">node</span><span class="p">,</span> <span class="n">functions</span><span class="p">):</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
        <span class="n">ops</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stack_terminas</span><span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">node_data</span><span class="p">])</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="k">for</span> <span class="n">child</span> <span class="ow">in</span> <span class="n">node</span><span class="o">.</span><span class="n">childs</span><span class="p">:</span>
            <span class="n">_nodeops</span><span class="p">(</span><span class="n">ops</span><span class="p">,</span> <span class="n">child</span><span class="p">,</span> <span class="n">functions</span><span class="p">)</span>
        <span class="n">ops</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">stack_functions</span><span class="p">[</span><span class="n">node</span><span class="o">.</span><span class="n">node_data</span><span class="p">])</span>
</pre></div>
</div>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">eval_stack</span><span class="p">(</span><span class="n">chromosome</span><span class="p">):</span>
    <span class="n">error_accum</span> <span class="o">=</span> <span class="n">Util</span><span class="o">.</span><span class="n">ErrorAccumulator</span><span class="p">()</span>
    <span class="n">root</span> <span class="o">=</span> <span class="n">chromosome</span><span class="o">.</span><span class="n">getRoot</span><span class="p">()</span>
    <span class="n">ops</span> <span class="o">=</span> <span class="n">nodeops</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="n">functions</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">a</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
        <span class="k">for</span> <span class="n">b</span> <span class="ow">in</span> <span class="nb">xrange</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">5</span><span class="p">):</span>
            <span class="n">a</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
            <span class="n">b</span> <span class="o">=</span> <span class="nb">float</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
            <span class="c"># The eval will execute a pre-compiled syntax tree</span>
            <span class="c"># as a Python expression, and will automatically use</span>
            <span class="c"># the &quot;a&quot; and &quot;b&quot; variables (the terminals defined)</span>
            <span class="n">evaluated</span>     <span class="o">=</span> <span class="n">eval_ops</span><span class="p">(</span><span class="n">ops</span><span class="p">,</span> <span class="p">{</span><span class="s">&#39;a&#39;</span><span class="p">:</span><span class="n">a</span><span class="p">,</span> <span class="s">&#39;b&#39;</span><span class="p">:</span><span class="n">b</span><span class="p">})</span>
            <span class="n">target</span>        <span class="o">=</span> <span class="n">math</span><span class="o">.</span><span class="n">sqrt</span><span class="p">((</span><span class="n">a</span><span class="o">*</span><span class="n">a</span><span class="p">)</span><span class="o">+</span><span class="p">(</span><span class="n">b</span><span class="o">*</span><span class="n">b</span><span class="p">))</span>
            <span class="n">error_accum</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">evaluated</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">error_accum</span><span class="o">.</span><span class="n">getRMSE</span><span class="p">()</span>
</pre></div>
</div>
</div></blockquote>
<div class="section" id="resultate-des-geschwindigkeit-vergleiches">
<h3>Resultate des Geschwindigkeit Vergleiches</h3>
<p>Um einen Eindruck über die Geschwindigkeit der Verschiedenen Evaluierung Methoden
zu gewinnen, wurden sie vor das gleiche Problem gestellt.
Zusätzlich wurde neben dem normalen Python Interpreter
auch PyPy in den Vergleich mit einbezogen, um einen Eindruck zu gewinnen,
welchen Einfluss ein Python Interpreter mit JIT hat.</p>
<div class="highlight-python"><pre>pypy-bin stack
  real 1m48.747s
  user 1m47.867s
  sys 0m0.284s
pypy-bin visit
  real 2m44.631s
  user 2m43.050s
  sys 0m0.684s
pypy-bin code
  real 5m24.300s
  user 5m21.348s
  sys 0m1.460s
python stack
  real 8m28.568s
  user 8m25.172s
  sys 0m1.340s
python visit
  real 12m28.534s
  user 12m22.086s
  sys 0m1.620s
python code
  real 11m37.197s
  user 11m33.135s
  sys 0m1.212s

</pre>
</div>
</div>
<div class="section" id="demonstration-der-eigenheiten-des-algorithmus">
<h3>Demonstration der Eigenheiten des Algorithmus</h3>
<p>Um diverse Eigenheiten zu demonstrieren,
wurden gewinnende Individuen aus Verschiedenen Generationen entnommen</p>
<ol class="arabic simple">
<li>Tote Teile des Genoms</li>
</ol>
<blockquote>
<div><div class="highlight-python"><div class="highlight"><pre><span class="n">add</span><span class="p">(</span>
  <span class="n">mul</span><span class="p">(</span>
    <span class="n">sub</span><span class="p">(</span>
      <span class="n">sub</span><span class="p">(</span><span class="n">add</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">)),</span>
      <span class="n">sub</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">sub</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">))),</span>
    <span class="n">sqrt</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span><span class="n">mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)))),</span>
  <span class="n">sqrt</span><span class="p">(</span><span class="n">add</span><span class="p">(</span>
    <span class="n">add</span><span class="p">(</span><span class="n">mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">)),</span>
    <span class="n">mul</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">a</span><span class="p">))))</span>
</pre></div>
</div>
<p>In diesem Beispiel ist die Sequenz <cite>sub(b, b)</cite> der &quot;Fehler&quot;
es ist ein typischer Auslöschung Fehler, der das eigentliche Ergebnis nicht ändert</p>
</div></blockquote>
<ol class="arabic simple" start="2">
<li>Fehler Daten bei zuwenig Generationen</li>
</ol>
<blockquote>
<div><p>Folgend ist das beste Individuum bei einem lauf mit 50 Fenerationen</p>
<p>es ist unschwer zu erkennen, dass es weit vom Optimum entfernt ist</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">sqrt</span><span class="p">(</span><span class="n">add</span><span class="p">(</span>
  <span class="n">sqrt</span><span class="p">(</span><span class="n">mul</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">a</span><span class="p">))),</span>
  <span class="n">add</span><span class="p">(</span>
    <span class="n">mul</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">),</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">b</span><span class="p">)),</span>
    <span class="n">add</span><span class="p">(</span><span class="n">mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">)))))</span>
</pre></div>
</div>
</div></blockquote>
<ol class="arabic simple" start="3">
<li>Fehler Daten bei zu geringer Population</li>
</ol>
<blockquote>
<div><p>Folgend ist das beste Individuum wenn die Populationsgrösse stark reduziert ist</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">add</span><span class="p">(</span>
  <span class="n">sqrt</span><span class="p">(</span><span class="n">add</span><span class="p">(</span>
    <span class="n">mul</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">b</span><span class="p">),</span> <span class="n">add</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">)),</span>
    <span class="n">sub</span><span class="p">(</span><span class="n">sqrt</span><span class="p">(</span><span class="n">b</span><span class="p">),</span> <span class="n">a</span><span class="p">))),</span>
  <span class="n">sqrt</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">sqrt</span><span class="p">(</span><span class="n">a</span><span class="p">))))</span>
</pre></div>
</div>
</div></blockquote>
</div>
</div>
<div class="section" id="resultat-eines-erfolgreichen-durchlaufes">
<h2>Resultat eines Erfolgreichen Durchlaufes</h2>
<dl class="docutils">
<dt>500 Generationen</dt>
<dd><div class="first last highlight-python"><div class="highlight"><pre><span class="n">sqrt</span><span class="p">(</span><span class="n">sub</span><span class="p">(</span>
  <span class="n">sub</span><span class="p">(</span><span class="n">add</span><span class="p">(</span><span class="n">mul</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">a</span><span class="p">),</span> <span class="n">mul</span><span class="p">(</span><span class="n">b</span><span class="p">,</span> <span class="n">b</span><span class="p">)),</span> <span class="n">a</span><span class="p">),</span> <span class="n">a</span><span class="p">))</span>
</pre></div>
</div>
</dd>
<dt>1000 Generationen</dt>
<dd>sqrt(add(add(mul(b, b), mul(a, a)), mul(sub(b, b), mul(sub(a, a), sub(b, a)))))</dd>
<dt>2000 Generationen 2000 Population</dt>
<dd>sqrt(add(add(mul(b, b), mul(a, a)), mul(add(add(b, a), a), mul(mul(a, a), sub(a, a)))))</dd>
<dt>40 gen, 2000 Items, Kosten für Tiefe</dt>
<dd>sqrt(add(mul(b, b), mul(a, a)))</dd>
</dl>
<p>Beispiel schneller erfolgreicher Durchlaufe:</p>
<div class="highlight-python"><pre>$ PYTHONPATH=../pyevolve/ pypy-bin funfind.py stack \
&gt;           --generations 2000 \
&gt;           --population 2000 \
&gt;           --height-weight=0.00000001
Gen. 0 (0.00%): Max/Min/Avg Fitness(Raw) [1575.10(640067.30)/1312.04(0.72)/1312.58(1312.58)]
Gen. 20 (1.00%): Max/Min/Avg Fitness(Raw) [5.18(927.35)/4.32(0.70)/4.32(4.32)]
Gen. 40 (2.00%): Max/Min/Avg Fitness(Raw) [6.80(1388.24)/5.66(0.61)/5.67(5.67)]
Gen. 60 (3.00%): Max/Min/Avg Fitness(Raw) [6.52(3972.74)/5.43(0.00)/5.43(5.43)]
^C
  A break was detected, you have interrupted the evolution !

Gen. 72 (3.60%): Max/Min/Avg Fitness(Raw) [4.99(1178.43)/4.16(0.00)/4.16(4.16)]
Total time elapsed: 21.301 seconds.
sqrt(add(mul(b, b), mul(a, a)))</pre>
</div>
</div>
</div>
<div class="section" id="der-grosse-kombinatorische-test">
<h1>Der grosse kombinatorische Test</h1>
<p>Um das Verhalten des Algorithmus besser zu verstehen,
wurde er für eine grosse Menge an Konfigurationen jeweils komplett durchgeführt.</p>
<p>Dabei wurden folgende fixen Achsen verwendet:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">crossover rate:</th><td class="field-body">1.0</td>
</tr>
<tr class="field-even field"><th class="field-name">mutation rate:</th><td class="field-body">0.08</td>
</tr>
<tr class="field-odd field"><th class="field-name">height shift:</th><td class="field-body">-3</td>
</tr>
</tbody>
</table>
<p>Die <cite>height shift</cite> ist dabei der Wert um den die Baum höhe
verändert wird, bevor sie in die Gewichtung eingeht.</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">def</span> <span class="nf">eval_height</span><span class="p">(</span><span class="n">chromosome</span><span class="p">):</span>
    <span class="k">return</span> <span class="nb">abs</span><span class="p">(</span><span class="n">chromosome</span><span class="o">.</span><span class="n">tree_height</span><span class="o">-</span><span class="mi">3</span><span class="p">)</span>
</pre></div>
</div>
<p>Der Wert von -3 wurde gewählt, weil die optimale Baum höhe im
Beispiel ist und versucht wird, das Bewertung Ergebnis zu minimieren.</p>
<p>Die Dynamischen Achsen sind:</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field-odd field"><th class="field-name">height-weight:</th><td class="field-body">[-2,-1,-0.1,-0.01,-0.001,0,0.001,0.01,0.1,1,2]</td>
</tr>
<tr class="field-even field"><th class="field-name">generations:</th><td class="field-body">[20,50,100,300,500,1000,1500,2000,3000,5000]</td>
</tr>
<tr class="field-odd field"><th class="field-name">population:</th><td class="field-body">[20,50,100,300,500,1000,1500,2000,3000,5000]</td>
</tr>
</tbody>
</table>
<p><cite>height-weight</cite> gibt dabei ein, wie stark die bereits erwähnte Baum höhe
in die Bewertung mit eingeht.</p>
<p>Um einen groben Überblick zu erlangen,
wurden für alle Kombinationen von height-weight,
Plots über Generationen X Population erstellt,
und korrekte/inkorrekte Resultate markiert.</p>
<p>Dabei wurde nur ein optimales Ergebnis als korrekt angesehen
(i.e. <cite>sqrt(add(mul(a, a), mul(b, b)))</cite>
oder <cite>sqrt(add(mul(b, b) mul(a, a)))</cite>).</p>
<p>Alle Plots sind in der zugefügten <a class="reference external" href="./fill_run.html">datei</a> einsehbar.</p>
<p>Da alle Ergebnisse grosse Ähnlichkeit aufweisen
(weight_height scheint keinen visuell feststellbaren Einfluss zu haben),
wurde das Beispiel mit der Gewichtung 0 gewählt.</p>
<style>
  .correct {background-color: green;}
  .incorrect {background-color: red;}
</style>
<h2>heights weight 0</h2>
<table>
  <tr>
    <th>*
  <th>20
  <th>50
  <th>100
  <th>300
  <th>500
  <th>1000
  <th>1500
  <th>2000
  <th>3000
  <th>5000
  <tr><th>20
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
  <tr><th>50
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
  <tr><th>100
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=incorrect>&nbsp
  <tr><th>300
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
  <tr><th>500
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
  <tr><th>1000
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
  <tr><th>1500
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
  <tr><th>2000
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
  <tr><th>3000
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
  <tr><th>5000
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=incorrect>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
    <td class=correct>&nbsp
</table>
</div>
<div class="section" id="fazit">
<h1>Fazit</h1>
<p>Anhand des Datensatzes ist recht einleuchtend der Effekt von Zufallstreffern,
sowie zunehmender Menge von Generationen und Population zu erkennen.</p>
<p>Die gewonnenen Daten legen nahe,
dass die Qualität des Ergebnisses in direkter Relation mit
der Menge an Generationen und Population steht.</p>
<p>Die Gewichtung der Baum höhe hatte keinen Effekt.</p>
</div>
<div class="section" id="selbstkritik">
<h1>Selbstkritik</h1>
<p>Bisher konnten weitere interessante Grössen zur Parametrisierung noch
nicht analysiert werden.
Besonders interessant sind dabei cross-over rate und Mutationsrate.</p>
<p>Entgegen der auf den Beispielen für Eigenarten basierenden Erwartung,
dass die Höhe des Baumes einen Einfluss hat,
stellte sich heraus, dass sie keinen hat.</p>
<p>Weiterhin ist nicht klar,
welchen Einfluss die Komplexität der Funktion auf das Ergebnis hat.</p>
<p>Der hohe Aufwand an Rechenzeit legt weitere Projekte nahe.</p>
</div>
</div>
</body>
</html>