diff --git a/ea/Ub5/EvA2_Symbolic_Regression_problem+GA_Mon_2015.06.22_at_21.41.14.txt b/ea/Ub5/EvA2_Symbolic_Regression_problem+GA_Mon_2015.06.22_at_21.41.14.txt new file mode 100644 index 0000000..09c8305 --- /dev/null +++ b/ea/Ub5/EvA2_Symbolic_Regression_problem+GA_Mon_2015.06.22_at_21.41.14.txt @@ -0,0 +1,142 @@ +StartDate:Mon_2015.06.22_at_21.41.14 +On Host:localhost + +****** Multirun 0 +Module parameters: + eva2.server.modules.GOParameters{ + optimizer= + eva2.server.go.strategies.GeneticAlgorithm{ + elitism= true; + numberOfPartners= 1; + parentSelection= + eva2.server.go.operators.selection.SelectBestIndividuals{ + obeyDebsConstViolationPrinciple= true; }; + partnerSelection= + eva2.server.go.operators.selection.SelectBestIndividuals{ + obeyDebsConstViolationPrinciple= true; }; + population= + eva2.server.go.populations.Population{ + initAround= 0.1; + initMethod= individualDefault; + initPos=[ + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 + 0.0 ]; + popMetric= + eva2.server.go.operators.distancemetric.PhenotypeMetric{}; + seedCardinality= (5,1); + targetSize= 5; }; }; + postProcessParams= + eva2.server.go.operators.postprocess.PostProcessParams{ + PPMethod= nelderMead; + accAssumeConv= 1.0E-8; + accMaxEval= -1; + accuracies=[ + 0.01 ]; + doPostProcessing= false; + postProcessClusterSigma= 0.05; + postProcessSteps= 5000; + printNBest= 10; + withPlot= false; }; + problem= + eva2.server.go.problems.PSymbolicRegression{ + GPIndividual= + eva2.server.go.individuals.GPIndividualProgramData{ + checkMaxDepth= true; + crossoverOperator= + eva2.server.go.operators.crossover.CrossoverGPDefault{}; + crossoverProbability= 1.0; + initDepth= 4; + initFullGrowRatio= 0.5; + initOperator= + eva2.server.go.operators.initialization.DefaultInitialization{}; + maxAllowedDepth= 8; + mutationOperator= + eva2.server.go.operators.mutation.MutateDefault{}; + mutationProbability= 0.2; }; + area= + eva2.server.go.individuals.codings.gp.GPArea{}; + defaultAccuracy= 0.001; + lowerBound= -1.0; + noise= 0.0; + numberOfCheckPoints= 20; + numberOfConstants= 3; + parallelThreads= 1; + showResult= false; + targetFunction= + eva2.server.go.problems.regression.RFKoza_GPI_7_3{}; + upperBound= 1.0; + useInnerConst= false; + useLocalHillClimbing= false; }; + seed= 500; + terminator= EvaluationTerminator,calls=50; } +Statistics parameters: +StatParameter (eva2.server.stat.StatsParameter@5d4bebf2): +m_MultiRuns=25, m_Textoutput=0, verbosity= Final results +To Both file and text-window, [ currentBest meanFit currentWorst runBest currentBestFeasible runBestFeasible avgEucPopDistance maxEucPopDistance avgPopMetricDist maxPopMetricDist bestIndySize avgIndySize avgMaxIndyDepth solution ] +......................... +******* + Runs performed: 25, reached target 0 times with threshold 0.001, rate 0.0 + Average function calls: 50 + Feasible solution found in 25 of 25 runs + Average evaluations until feasible ind. was found in 25 runs: 5.0 evaluations + Averaged sum of run statistical data: (25 runs): 275.0 8.400622756773501 Infinity Infinity 8.400622756773501 8.360749160571213 8.351795085633176 6.609306749047762 8.941275280968748 6.609306749047762 8.941275280968748 69.28 81.59200000000004 30.28800000000002 + Averaged last statistical data (25 runs): 50.0 0.6855228285681008 Infinity 6.153062138700972E52 0.6855228285681008 0.6855228285681008 0.6855228285681008 0.6394906253532291 0.895327423841355 0.6394906253532291 0.895327423841355 7.8 8.816 3.032000000000001 +* Overall best ind.: eva2.server.go.individuals.GPIndividualProgramData{checkMaxDepth=true; crossoverOperator=eva2.server.go.operators.crossover.CrossoverGPDefault{}; crossoverProbability=1.0; initDepth=4; initFullGrowRatio=0.5; initOperator=eva2.server.go.operators.initialization.DefaultInitialization{}; maxAllowedDepth=8; mutationOperator=eva2.server.go.operators.mutation.MutateDefault{}; mutationProbability=0.2; } + solution data : {*(exp(*(exp(*(+(*(cos(pi), /(X0, X0)), exp(cos(pi))), cos(exp(cos(X0))))), /(X0, exp(1.0)))), /(X0, 1.0))} + solution fit : [ 0.2990970182485838 ] +Overall best statistical data: FunctionCalls currentBest meanFit currentWorst runBest currentBestFeasible runBestFeasible avgEucPopDistance maxEucPopDistance avgPopMetricDist maxPopMetricDist bestIndySize avgIndySize avgMaxIndyDepth solution +50 0.7550460726670315 1.1419887756849643 1.6104768934863931 0.7550460726670315 0.7550460726670315 0.7550460726670315 0.5733333333333334 0.8 0.5733333333333334 0.8 26 26.0 8.0 {*(exp(*(exp(*(+(*(cos(pi), /(X0, X0)), exp(cos(pi))), cos(exp(cos(X0))))), /(X0, exp(1.0)))), /(X0, 1.0))} + MultiRun stats: Mean best fitness: [ 0.6855228285681008 ] + MultiRun stats: Variance/Std.Dev.: [ 0.03724707215824555 0.19299500552668597 ] + MultiRun stats: Median best fitn.: [ 0.6882283083722263 ] +* Overall best feasible ind.: eva2.server.go.individuals.GPIndividualProgramData{checkMaxDepth=true; crossoverOperator=eva2.server.go.operators.crossover.CrossoverGPDefault{}; crossoverProbability=1.0; initDepth=4; initFullGrowRatio=0.5; initOperator=eva2.server.go.operators.initialization.DefaultInitialization{}; maxAllowedDepth=8; mutationOperator=eva2.server.go.operators.mutation.MutateDefault{}; mutationProbability=0.2; } + solution data : {*(exp(*(exp(*(+(*(cos(pi), /(X0, X0)), exp(cos(pi))), cos(exp(cos(X0))))), /(X0, exp(1.0)))), /(X0, 1.0))} + solution fit : [ 0.2990970182485838 ] + MultiRun stats: Mean best feasible fitness (25 runs): [ 0.6855228285681008 ] + MultiRun stats: Variance/Std.Dev.: [ 0.03724707215824555 0.19299500552668597 ] + MultiRun stats: Median best feasible fitn. (: 25 runs): [ 0.6882283083722263 ] + Averaged performance: +Iteration FunctionCalls currentBest meanFit currentWorst runBest currentBestFeasible runBestFeasible avgEucPopDistance maxEucPopDistance avgPopMetricDist maxPopMetricDist bestIndySize avgIndySize avgMaxIndyDepth solution +1 5.0 1.2795816187535172 Infinity Infinity 1.2795816187535172 1.2397080225512314 1.2397080225512314 0.6903165524689627 0.8440965651536605 0.6903165524689627 0.8440965651536605 5.04 6.368 2.44 null +2 10.0 1.063303788413066 Infinity 8.6448698282437714E18 1.063303788413066 1.063303788413066 1.0543497134750286 0.6627100833601157 0.8661611016927353 0.6627100833601157 0.8661611016927353 5.16 6.400000000000001 2.5920000000000005 null +4 20.0 0.8091207454979861 Infinity 1.19330549446887008E17 0.8091207454979861 0.8091207454979861 0.8091207454979861 0.6595147964758281 0.8990485732182661 0.6595147964758281 0.8990485732182661 7.12 8.472000000000001 3.248 null +5 25.0 0.7866911871039517 Infinity 3.3298289896083443E44 0.7866911871039517 0.7866911871039517 0.7866911871039517 0.6894611955530965 0.9261016612706624 0.6894611955530965 0.9261016612706624 7.04 8.463999999999999 3.0720000000000005 null +6 30.0 0.7379298303569312 2.3164752873104317E49 1.158237643655216E50 0.7379298303569312 0.7379298303569312 0.7379298303569312 0.6454089145206032 0.9043429050489746 0.6454089145206032 0.9043429050489746 7.48 8.064 3.0879999999999996 null +7 35.0 0.7325527789441466 1.968272036263038E159 9.841360181315191E159 0.7325527789441466 0.7325527789441466 0.7325527789441466 0.6569655500823934 0.9191179222969389 0.6569655500823934 0.9191179222969389 7.24 9.264 3.4239999999999986 null +9 45.0 0.6855228285681008 1.0126711343471039E50 5.06335567173552E50 0.6855228285681008 0.6855228285681008 0.6855228285681008 0.6300223170055239 0.8858683221020018 0.6300223170055239 0.8858683221020018 7.8 9.175999999999998 3.200000000000001 null +10 50.0 0.6855228285681008 Infinity 6.153062138700972E52 0.6855228285681008 0.6855228285681008 0.6855228285681008 0.6394906253532291 0.895327423841355 0.6394906253532291 0.895327423841355 7.8 8.816 3.032000000000001 null + Last data line of 25 multi-runs: +[ 50 0.40629024192837954 140.6119466321498 683.6589376996856 0.40629024192837954 0.40629024192837954 0.40629024192837954 0.6187161843752111 0.8663366336633663 0.6187161843752111 0.8663366336633663 40 31.8 6.6 {+(/(-(exp(1.0), *(exp(exp(X0)), 1.0)), +(sin(pi), *(-(-(cos(sin(1.0)), 1.0), +(sin(sin(pi)), +(exp(1.0), cos(X0)))), +(+(sin(exp(pi)), 1.0), -(pi, sin(X0)))))), X0)} ] +[ 50 0.4094143718644114 1.6566192189280708 4.463387904275842 0.4094143718644114 0.4094143718644114 0.4094143718644114 0.6193939393939394 0.9 0.6193939393939394 0.9 6 4.4 2.0 {*(+(1.0, cos(X0)), X0)} ] +[ 50 0.8481327769932886 3.739912251983024 14.90157754766671 0.8481327769932886 0.8481327769932886 0.8481327769932886 0.6895555920872376 0.9113924050632911 0.6895555920872376 0.9113924050632911 6 7.4 3.0 {+(sin(X0), /(X0, 1.0))} ] +[ 50 0.3534769916246338 2437.9284079424656 12187.201141710293 0.3534769916246338 0.3534769916246338 0.3534769916246338 0.7026030569708199 0.984251968503937 0.7026030569708199 0.984251968503937 5 9.0 2.6 {*(X0, +(X0, 1.0))} ] +[ 50 0.978897946117972 9.456832583796524 42.73232599315627 0.978897946117972 0.978897946117972 0.978897946117972 0.6489951489951491 0.9819819819819819 0.6489951489951491 0.9819819819819819 1 7.6 2.2 {X0} ] +[ 50 0.7829751334608502 1.844258485437728 2.5944761324768697 0.7829751334608502 0.7829751334608502 0.7829751334608502 0.4510844917677216 0.6326530612244898 0.4510844917677216 0.6326530612244898 11 13.0 7.6 {-(X0, cos(sin(sin(sin(-(exp(pi), sin(X0)))))))} ] +[ 50 0.8457004401293784 1.733294316328553 4.770745027565671 0.8457004401293784 0.8457004401293784 0.8457004401293784 0.7358209030641117 0.9583333333333334 0.7358209030641117 0.9583333333333334 5 5.6 2.2 {+(cos(X0), cos(X0))} ] +[ 50 0.6882283083722263 2.678099543425216 10.34691484589143 0.6882283083722263 0.6882283083722263 0.6882283083722263 0.5673469387755101 0.9591836734693877 0.5673469387755101 0.9591836734693877 2 3.8 1.8 {exp(X0)} ] +[ 50 0.7550460726670315 1.0787630969055617 1.6104768934863931 0.7550460726670315 0.7550460726670315 0.7550460726670315 0.4116841491841491 0.625 0.4116841491841491 0.625 7 4.6 1.8 {*(1.0, +(*(1.0, X0), 1.0))} ] +[ 50 0.8603092305617682 0.9077447167842496 0.978897946117972 0.8603092305617682 0.8603092305617682 0.8603092305617682 0.4666666666666667 0.7777777777777778 0.4666666666666667 0.7777777777777778 3 2.2 0.6 {+(X0, X0)} ] +[ 50 0.6344120730044255 2.3954453578281596 5.768347201398037 0.6344120730044255 0.6344120730044255 0.6344120730044255 0.779374718848403 0.9829059829059829 0.779374718848403 0.9829059829059829 5 9.6 3.2 {+(exp(cos(X0)), X0)} ] +[ 50 0.978897946117972 3.185593173760388E14 1.5927965868801475E15 0.978897946117972 0.978897946117972 0.978897946117972 0.636031746031746 0.8666666666666667 0.636031746031746 0.8666666666666667 1 2.6 1.0 {X0} ] +[ 50 0.5107848758622829 1826.6637986519204 9127.58693986167 0.5107848758622829 0.5107848758622829 0.5107848758622829 0.728402756967336 0.925531914893617 0.728402756967336 0.925531914893617 17 10.4 4.2 {*(*(/(cos(1.0), exp(sin(/(sin(cos(pi)), X0)))), exp(sin(X0))), sin(X0))} ] +[ 50 0.2990970182485838 48.651286320426344 238.75826882296525 0.2990970182485838 0.2990970182485838 0.2990970182485838 0.8002830026359439 0.9809523809523809 0.8002830026359439 0.9809523809523809 26 11.0 4.0 {*(exp(*(exp(*(+(*(cos(pi), /(X0, X0)), exp(cos(pi))), cos(exp(cos(X0))))), /(X0, exp(1.0)))), /(X0, 1.0))} ] +[ 50 0.608867448005736 14.322639187128516 66.22795082697021 0.608867448005736 0.608867448005736 0.608867448005736 0.5863441734417345 0.8166666666666667 0.5863441734417345 0.8166666666666667 6 7.8 3.6 {+(sin(sin(cos(1.0))), X0)} ] +[ 50 0.6882283083722263 6.941351294953128 31.663173603530993 0.6882283083722263 0.6882283083722263 0.6882283083722263 0.6012175324675324 0.9886363636363636 0.6012175324675324 0.9886363636363636 2 10.4 2.2 {exp(X0)} ] +[ 50 0.8369373077871817 1.115682941522143 1.7939087699990828 0.8369373077871817 0.8369373077871817 0.8369373077871817 0.6555950715950716 0.978021978021978 0.6555950715950716 0.978021978021978 6 8.6 4.2 {exp(cos(sin(/(X0, 1.0))))} ] +[ 50 0.6197601416485382 3.0765310693504856E53 1.538265534675243E54 0.6197601416485382 0.6197601416485382 0.6197601416485382 0.744633192528546 0.9496402877697842 0.744633192528546 0.9496402877697842 6 14.8 4.4 {+(exp(X0), cos(sin(X0)))} ] +[ 50 0.8603092305617682 2.283871506595834 5.174650717161607 0.8603092305617682 0.8603092305617682 0.8603092305617682 0.6155555555555556 0.9459459459459459 0.6155555555555556 0.9459459459459459 11 8.0 2.6 {+(-(X0, X0), +(-(X0, X0), +(X0, X0)))} ] +[ 50 0.4511578881644988 2.610873086313289E15 1.3054365431566434E16 0.4511578881644988 0.4511578881644988 0.4511578881644988 0.6640154960355544 0.8617021276595744 0.6640154960355544 0.8617021276595744 9 22.0 5.8 {*(*(X0, sin(-(pi, X0))), exp(X0))} ] +[ 50 0.6882283083722263 5.061865021492222 21.97507259848071 0.6882283083722263 0.6882283083722263 0.6882283083722263 0.646583850931677 0.9565217391304348 0.646583850931677 0.9565217391304348 2 3.4 1.2 {exp(X0)} ] +[ 50 0.6882283083722263 Infinity 2.647619652262746 0.6882283083722263 0.6882283083722263 0.6882283083722263 0.5929971988795518 0.8095238095238095 0.5929971988795518 0.8095238095238095 2 3.6 2.2 {exp(X0)} ] +[ 50 0.6107463271799114 2.592165218844859 7.040513266102282 0.6107463271799114 0.6107463271799114 0.6107463271799114 0.7009614781353912 0.9761904761904762 0.7009614781353912 0.9761904761904762 12 11.8 4.2 {+(/(exp(X0), /(X0, sin(/(X0, 1.0)))), cos(X0))} ] +[ 50 0.978897946117972 2.2231095600048763 5.433954301427349 0.978897946117972 0.978897946117972 0.978897946117972 0.7500694551628339 0.9473684210526315 0.7500694551628339 0.9473684210526315 1 5.2 2.2 {X0} ] +[ 50 0.7550460726670315 1.1419887756849643 1.6104768934863931 0.7550460726670315 0.7550460726670315 0.7550460726670315 0.5733333333333334 0.8 0.5733333333333334 0.8 3 1.8 0.4 {+(1.0, X0)} ] +StopDate:Mon_2015.06.22_at_21.41.14 diff --git a/ea/Ub5/GOParameters.ser b/ea/Ub5/GOParameters.ser index 2422490..6e233bc 100644 --- a/ea/Ub5/GOParameters.ser +++ b/ea/Ub5/GOParameters.ser Binary files differ diff --git a/ea/Ub5/Statistics.ser b/ea/Ub5/Statistics.ser index 4661123..175b000 100644 --- a/ea/Ub5/Statistics.ser +++ b/ea/Ub5/Statistics.ser Binary files differ diff --git a/ea/ub8/framework/gp/DummyGPIndividual.java b/ea/ub8/framework/gp/DummyGPIndividual.java index 8a0c5a2..8e6c547 100644 --- a/ea/ub8/framework/gp/DummyGPIndividual.java +++ b/ea/ub8/framework/gp/DummyGPIndividual.java @@ -29,7 +29,6 @@ @Override public DummyGPIndividual makeRandomSubtree(int h, int mode) { - // ja da habt ihr ne nette endlosschleife programmiert return new DummyGPIndividual(this, h - 1, mode); diff --git a/ea/ub8/framework/gp/EvolutionaryAlgorithm.java b/ea/ub8/framework/gp/EvolutionaryAlgorithm.java index 486a7e6..e8e40ed 100644 --- a/ea/ub8/framework/gp/EvolutionaryAlgorithm.java +++ b/ea/ub8/framework/gp/EvolutionaryAlgorithm.java @@ -42,7 +42,7 @@ // indies[i] = new DummyGPIndividual(6, GPTree.MODE_GROW); // TODO: Replace with RegrIndividual indies[i] = new RegrIndividual(6, GPTree.MODE_GROW); - indies[i].defaultInit(); + // indies[i].defaultInit(); changed } } diff --git a/ea/ub8/framework/gp/GPTree.java b/ea/ub8/framework/gp/GPTree.java index 46bff3f..1da7f1e 100644 --- a/ea/ub8/framework/gp/GPTree.java +++ b/ea/ub8/framework/gp/GPTree.java @@ -15,8 +15,10 @@ public static int MODE_GROW = 1; public Random ran = new Random(); + // schonmal was von Javadoc für public Felder gehört?? Ihr könnt doch + // Schnittstellen nicht unkommentiert lassen. public int arity; // Stelligkeit des Knotens aha! - public int type; // Knotentyp . Schon mal was von Enums gehört... + protected int type; // Knotentyp . Schon mal was von Enums gehört... public int height; // Hoehe des Baumes public int nodeCount; // Knotenanzahl in diesem Baum public GPTree up, left, right; // Zeiger auf Eltern- und Unterknoten @@ -49,18 +51,25 @@ * Dieser Konstruktor erzeugt mit Hilfe von copyTree() eine tiefe Kopie * des Baumes tree. */ + if (!tree.isValid()) { + throw new RuntimeException("not valid tree to copy"); + } this.arity = tree.arity; this.type = tree.type; this.height = tree.height; this.nodeCount = tree.nodeCount; - if (left != null) { - left = copyTree(left); + this.up = tree.up; + if (tree.left != null) { + left = copyTree(tree.left); left.up = this; } - if (right != null) { - right = copyTree(right); + if (tree.right != null) { + right = copyTree(tree.right); right.up = this; } + if (!this.isValid()) { + throw new RuntimeException("after copy no valid tree"); + } } /** @@ -80,9 +89,9 @@ */ // :-D :-D whooo das kommentar ist der hammer, da hat einer Vererbung // und Typen einfach nicht verstanden - if (maxH > 0) { - parent = makeRandomSubtree(maxH, mode);// TODO mode - } + + this.up = parent; + makeRandomSubtree(maxH, mode); } @@ -93,6 +102,8 @@ // ************* abstract methods // these two are abstract so that the subtypes can return the right type // they should again use GPTree's (copy) constructor! + + // na wie wärs den mit Javadoc ??? public abstract GPTree makeRandomSubtree(int h, int mode); public abstract GPTree copyTree(GPTree tree); @@ -101,7 +112,9 @@ public abstract int getTermCount(); // return number of terminals - public abstract int getUnaryCount(); // return number of unary functions + public abstract int getUnaryCount(); // return number of unary functions // + // Toller Javadoc, so als + // Kommentar... public abstract int getBinaryCount(); // return number of binary functions @@ -140,16 +153,51 @@ } switch (arity) { case 0: - return ((left == null) && (right == null) && (height == 0) && (nodeCount == 1)); + boolean a = ((left == null) && (right == null) && (height == 0) && (nodeCount == 1)); + if (!a) { + System.out.println(a + "case 0"); + System.out.println(left); + System.out.println(right); + System.out.println(height); + System.out.println(nodeCount); + System.out.println("_________"); + } + return a; case 1: - return ((left != null) && (right == null) + boolean b = ((left != null) + && (right == null) && (height == (left.height + 1)) - && (nodeCount == (left.nodeCount + 1)) && left.isValid() && (left.up == this)); + /* && (nodeCount == (left.nodeCount + 1)) */&& left + .isValid() && (left.up == this)); + if (!b) { + System.out.println(b + "case1"); + System.out.println("left" + left); + System.out.println("right " + right); + System.out + .println("height " + height + " " + (left.height + 1)); + System.out.println("nodecount " + nodeCount + " " + + (left.nodeCount + 1)); + System.out.println("parent " + (left.up == this)); + System.out.println("_________"); + } + return b; case 2: - return ((left != null) && (right != null) + boolean c = ((left != null) && (right != null) && (height == (Math.max(left.height, right.height) + 1)) - && (nodeCount == (left.nodeCount + right.nodeCount + 1)) + /* && (nodeCount == (left.nodeCount + right.nodeCount + 1)) */ && left.isValid() && right.isValid() && (left.up == this) && (right.up == this)); + if (!c) { + System.out.println(c + "case2"); + System.out.println("left" + left); + System.out.println("right " + right); + System.out.println("height " + height + " " + + (Math.max(left.height, right.height) + 1)); + System.out.println("nodecount " + nodeCount + " " + + (left.nodeCount + right.nodeCount + 1)); + System.out.println("parent " + (left.up == this)); + System.out.println("_________"); + } + return c; } return false; } @@ -169,24 +217,103 @@ * Hinweis: wählen Sie zuerst zwei zufällige Teilbäume von this und * otherTree. Dabei kann eine Vorstellung der Numerierung der * Unterknoten helfen. + * + * ist die maximale höhe der teilbäume gemeint? nichtmal gescheite + * javadoc gibts.. */ - GPTree os = findSubtree(ran.nextInt(nodeCount) + 1); - GPTree ts = findSubtree(ran.nextInt(nodeCount) + 1); - if (os.up.left.equals(os)) { - os.up.left = ts; - } else { - os.up.right = ts; + + if (!this.isValid()) { + + throw new RuntimeException(" this not valid before crossover"); } - if (ts.up.left.equals(ts)) { - ts.up.left = os; + if (!otherTree.isValid()) { + + throw new RuntimeException(" othertree not valid before crossover"); + } + + List thisTrees = new ArrayList(); + List otherTrees = new ArrayList(); + getAllTreesSameOrLower(this, h, thisTrees); + GPTree ts = null; + GPTree os = null; + if ((thisTrees.size() > 0)) { + ts = thisTrees.get(ran.nextInt(thisTrees.size())); } else { - ts.up.right = os; + return; + } + getAllTreesSameHight(otherTree, ts.height, otherTrees); + if ((otherTrees.size() > 0)) { + os = otherTrees.get(ran.nextInt(otherTrees.size())); + } else { + return; + } + if (os.up != null) { + os.up.nodeCount -= os.nodeCount; + os.up.nodeCount += ts.nodeCount; + + if (os.up.left.equals(os)) { + os.up.left = ts; + } else { + os.up.right = ts; + } + } + if (ts.up != null) { + ts.up.nodeCount -= ts.nodeCount; + ts.up.nodeCount += os.nodeCount; // todo notecount der eltern + // anpassen --> das wird jetzt + // echt zu viel code für die + // paar punkte . Wir ignorieren + // jetzt einfach den nodecount + // bei der prüfung braucht man + // eh nie + if (ts.up.left.equals(ts)) { + ts.up.left = os; + } else { + ts.up.right = os; + } } GPTree op = os.up; os.up = ts.up; ts.up = op; + if (!this.isValid()) { + throw new RuntimeException("this is not valid after crossover"); + } + if (!otherTree.isValid()) { + throw new RuntimeException( + "other tree is not valid after crossover"); + } + } + private void getAllTreesSameOrLower(GPTree start, int h, List result) { + if (start.height >= 0) { + if (start.height <= h) { + result.add(start); + } + if (start.left != null) { + getAllTreesSameOrLower(start.left, h, result); + } + if (start.right != null) { + getAllTreesSameOrLower(start.right, h, result); + } + } + }; + + private void getAllTreesSameHight(GPTree start, int h, List result) { + if (start.height >= h) { + if (start.height == h) { + result.add(start); + return; + } + if (start.left != null) { + getAllTreesSameHight(start.left, h, result); + } + if (start.right != null) { + getAllTreesSameHight(start.right, h, result); + } + } + }; + /** * @param pMut * propability of mutation @@ -204,46 +331,41 @@ // Wie ist das zu verstehen? eine zufällige Stelle dieses Teilbaums? if (ran.nextDouble() <= pMut) { - int index = ran.nextInt(nodeCount) + 1;// arraybaum index statet mit - // 1 - GPTree sub = findSubtree(index); - GPTree ne = makeRandomSubtree(h, mode); + GPTree sub = null; + GPTree ne = null; + List treesOfSameHight = new ArrayList(); + getAllTreesSameHight(this, h, treesOfSameHight); + if (treesOfSameHight.size() <= 0) { + return; + } + sub = treesOfSameHight.get(ran.nextInt(treesOfSameHight.size())); + ne = makeRandomSubtree(h, mode); // es wird immer nur ein Baum mit + // wieder der gleichen höhe + // erstellt wie der vorherige + // Hier funktioniert unser code nicht da makeRandom subtree nur this + // ändert und wir ja hier nicht auf subtypen casten können. + // So und hier geben wir es auf die Aufgabe zu lösen, mit der + // Hoffnung dass ihr uns nie wieder so schlecht kommentierten und so + // häufig gegen Java-Spezifikationen verstoßenden Code gebt wie + // diesen. + ne.up = sub.up; - if (sub.up.left.equals(sub)) { - ne.up.left = ne; - } else { - ne.up.right = ne; + if (ne.up != null) { + sub.up.nodeCount -= sub.nodeCount; + sub.up.nodeCount += ne.nodeCount; + if (sub.up.left.equals(sub)) { + sub.up.left = ne; + } else { + sub.up.right = ne; + } + sub.up = null; } - sub.up = null; } + if (!this.isValid()) { + System.err.println(this.toString() + " not valid mutation"); + throw new RuntimeException(""); + } } - /** - * @param index - * starts at 1 - * @return the GPTree at this index - */ - private GPTree findSubtree(int index) { - int cIndex = index; - List path = new ArrayList(); // geht sicher - // besser hab - // ich mir - // gerade selbst - // so gedacht - path.add(0, cIndex); - while (cIndex < 2) { - cIndex = cIndex / 2; - path.add(0, cIndex); - } - GPTree aimNode = this; - for (int i : path) { - if ((i % 2) == 0) { - aimNode = aimNode.left; - } else { - aimNode = aimNode.right; - } - } - return aimNode; - } } diff --git a/ea/ub8/framework/gp/RegrIndividual.java b/ea/ub8/framework/gp/RegrIndividual.java index 03a9aaa..aa6cd3d 100644 --- a/ea/ub8/framework/gp/RegrIndividual.java +++ b/ea/ub8/framework/gp/RegrIndividual.java @@ -7,12 +7,12 @@ public class RegrIndividual extends GPTree implements InterfaceIndividual { static String term[] = { "1", "x", "pi" }; static String unary[] = { "exp", "sin", "cos" }; - static String binary[] = { "+", "-", "*", "/" }; + static String binary[] = { "+", "-", "*" }; - int maxHeight = 5; - int initHeight = 3; - int modeCreate = MODE_GROW; - int modeMutate = MODE_GROW; + static int maxHeight = 5; + static int initHeight = 3; + static int modeCreate = MODE_GROW; + static int modeMutate = MODE_GROW; public RegrIndividual(GPTree parent, int h, int mode) { super(parent, h, mode); @@ -42,13 +42,14 @@ @Override public void crossover(InterfaceIndividual y) { - super.crossover((GPTree) y, maxHeight); + super.crossover((GPTree) y, this.height); } @Override public void mutate(double pMut) { - super.mutate(pMut, maxHeight, modeMutate); + super.mutate(pMut, this.height != 0 ? ran.nextInt(this.height) + 1 : 0, + modeMutate); } @Override @@ -64,21 +65,44 @@ @Override public GPTree makeRandomSubtree(int h, int mode) { - this.arity = ran.nextInt(3); + // System.out.println(); + if (h > 0) { // letzter Knoten hat höhe 0 + if ((mode == 0)) { + this.arity = ran.nextInt(2) + 1; + } else { + this.arity = ran.nextInt(3); + } + } else { + this.arity = 0; + } + switch (arity) { case 0: type = ran.nextInt(3); + nodeCount = 1; + height = 0; + left = null; + right = null; + break; case 1: type = ran.nextInt(3); left = new RegrIndividual(this, h - 1, mode); + left.up = this; + right = null; + nodeCount = left.nodeCount + 1; + height = left.height + 1; + break; case 2: - type = ran.nextInt(4); + type = ran.nextInt(3); left = new RegrIndividual(this, h - 1, mode); + left.up = this; right = new RegrIndividual(this, h - 1, mode); + right.up = this; + nodeCount = right.nodeCount + left.nodeCount + 1; + height = left.height > right.height ? left.height + 1 + : right.height + 1; + break; } - height = maxHeight - height; - nodeCount += 1;// Ka wie ich das bestimmen soll. - return this; } @@ -134,7 +158,7 @@ private double getF(double x) { RegrIndividual l = (RegrIndividual) left; RegrIndividual r = (RegrIndividual) right; - + // System.out.println(this); switch (arity) { case 0: switch (getTermSymbol(type)) { @@ -145,6 +169,7 @@ case "pi": return Math.PI; } + break; case 1: switch (getUnarySymbol(type)) { case "exp": @@ -155,6 +180,7 @@ return Math.cos(l.getF(x)); } + break; case 2: switch (getBinarySymbol(type)) { case "+": @@ -163,10 +189,9 @@ return l.getF(x) - r.getF(x); case "*": return l.getF(x) * r.getF(x); - case "/": - return l.getF(x) / r.getF(x); } + break; } throw new RuntimeException("wrong arity" + arity); diff --git a/mr/ub8/localize_ekf/motion_diff.m b/mr/ub8/localize_ekf/motion_diff.m index 1faaaa7..639976b 100644 --- a/mr/ub8/localize_ekf/motion_diff.m +++ b/mr/ub8/localize_ekf/motion_diff.m @@ -6,25 +6,31 @@ theta = x(3); sl = u(1); sr = u(2); - +if(sr~=sl) % YOUR CODE STARTS HERE % deltaTheta= (sr-sl)/l; r= (sl+sr)/(sr-sl) *l/2; + % fill this with the result of applying the motion model -if(sr==sl) + xnew= x+ [r*(sin(theta+deltaTheta)-sin(theta)); r*(-cos(theta+deltaTheta)-cos(theta)); deltaTheta]; + +G = [1,0,r*(cos(theta+deltaTheta)-cos(theta)); + 0,1,r*(sin(theta+deltaTheta)-sin(theta)); + 0,0,1]; else xnew= x+[sl*cos(theta); sl*sin(theta); 0]; +G = [1,0,r*(cos(theta+deltaTheta)-cos(theta)); + 0,1,r*(sin(theta+deltaTheta)-sin(theta)); + 0,0,1]; end % fill this with the motion Jacobian G % G=zeros(3,3) -G = [1,0,r*(cos(theta+deltaTheta)-cos(theta)); - 0,1,r*(sin(theta+deltaTheta)-sin(theta)); - 0,0,1]; + % YOUR CODE ENDS HERE %