Changeset 2674 for trunk/sources/HeuristicLab.GP.Tests
- Timestamp:
- 01/22/10 16:06:48 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.GP.Tests
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs
r2635 r2674 8 8 using HeuristicLab.Random; 9 9 using HeuristicLab.DataAnalysis; 10 using HeuristicLab.Common; 10 11 11 12 namespace HeuristicLab.GP.Test { … … 105 106 106 107 { 107 IFunctionTree tree = importer.Import("(open-+ (open-param - 0) (open-param - 0) (open-param- 0))");108 109 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 110 111 IFunctionTree t0 = importer.Import("(+ (variable 1.0 b 0) (variable 1.0 c 0))");112 IFunctionTree t1 = importer.Import("( - (variable 1.0 a 0) (variable 1.0 c 0))");113 IFunctionTree t2 = importer.Import("( - (variable 1.0 a 0) (variable 1.0 b 0))");114 115 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 116 t0, t1, t2 117 }); 118 } 119 120 { 121 IFunctionTree tree = importer.Import("(open-- (open-param - 0) (f1-+ (open-param - 0) 1.0) (f1-* (open-param- 0) 1.0))");122 123 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 124 125 IFunctionTree t0 = importer.Import("(- (+ (variable 1.0 b 0) 1.0) (* (variable 1.0 c 0) 1.0 ))");126 IFunctionTree t1 = importer.Import("( - (+ (variable 1.0 a 0) (* (variable 1.0 c 0) 1.0)) 1.0)");127 IFunctionTree t2 = importer.Import("( / (+ (variable 1.0 a 0) (+ (variable 1.0 b 0) 1.0)) 1.0)");128 129 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 130 t0, t1, t2 131 }); 132 } 133 134 { 135 IFunctionTree tree = importer.Import("(cycle (open-* (open-param - 0) (open-param - 0) (open-param- 0)))");136 137 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 138 139 IFunctionTree t0 = importer.Import("(* ( variable 1.0 b 0) (variable 1.0 c 0))");140 IFunctionTree t1 = importer.Import("( / (variable 1.0 a 0) (variable 1.0 c 0))");141 IFunctionTree t2 = importer.Import("(/ (variable 1.0 a 0) (variable 1.0 b 0))");142 143 144 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 145 t0, t1, t2 146 }); 147 } 148 149 150 { 151 IFunctionTree tree = importer.Import("(open-- (open-log (open-param - 0)) (open-exp (open-param - 0)) (open-param- 0))");108 IFunctionTree tree = importer.Import("(open-+ (open-param 1.0 - 0) (open-param 2.0 - 0) (open-param 4.0 - 0))"); 109 110 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 111 112 IFunctionTree t0 = importer.Import("(+ (variable 2.0 b 0) (variable 4.0 c 0))"); 113 IFunctionTree t1 = importer.Import("(* (- (variable 1.0 a 0) (variable 4.0 c 0)) 0.5)"); 114 IFunctionTree t2 = importer.Import("(* (- (variable 1.0 a 0) (variable 2.0 b 0)) 0.25)"); 115 116 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 117 t0, t1, t2 118 }); 119 } 120 121 { 122 IFunctionTree tree = importer.Import("(open-- (open-param 1.0 - 0) (f1-+ (open-param 2.0 - 0) 1.0) (f1-* (open-param 4.0 - 0) 1.0))"); 123 124 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 125 126 IFunctionTree t0 = importer.Import("(- (+ (variable 2.0 b 0) 1.0) (* (variable 4.0 c 0) 1.0 ))"); 127 IFunctionTree t1 = importer.Import("(* (- (+ (variable 1.0 a 0) (* (variable 4.0 c 0) 1.0)) 1.0 ) 0.5)"); 128 IFunctionTree t2 = importer.Import("(* (/ (+ (variable 1.0 a 0) (+ (variable 2.0 b 0) 1.0)) 1.0 ) 0.25)"); 129 130 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 131 t0, t1, t2 132 }); 133 } 134 135 { 136 IFunctionTree tree = importer.Import("(cycle (open-* (open-param 1.0 - 0) (open-param 2.0 - 0) (open-param 4.0 - 0)))"); 137 138 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 139 140 IFunctionTree t0 = importer.Import("(* (* (variable 4.0 b 0) (variable 1.0 c 0)) 0.5)"); 141 IFunctionTree t1 = importer.Import("(* (/ (variable 2.0 a 0) (variable 1.0 c 0)) 0.25)"); 142 IFunctionTree t2 = importer.Import("(/ (variable 2.0 a 0) (variable 4.0 b 0))"); 143 144 145 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { 146 t0, t1, t2 147 }); 148 } 149 150 151 { 152 IFunctionTree tree = importer.Import("(open-- (open-log (open-param 1.0 - 0)) (open-exp (open-param 1.0 - 0)) (open-param 1.0 - 0))"); 152 153 153 154 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 165 166 } 166 167 { 167 IFunctionTree tree = importer.Import("(open-- (open-log (open-log (open-param - 0))) (open-exp (open-exp (open-param - 0))) (f1-* (open-param- 0) 2.0))");168 IFunctionTree tree = importer.Import("(open-- (open-log (open-log (open-param 1.0 - 0))) (open-exp (open-exp (open-param 1.0 - 0))) (f1-* (open-param 1.0 - 0) 2.0))"); 168 169 169 170 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 181 182 } 182 183 { 183 IFunctionTree tree = importer.Import(@"(open-- (flip (open-log (open-param - 0)))184 (flip (f1-* (open-param - 0) 2.0))185 (flip (flip (f1-* (open-param - 0) 2.0))))");186 187 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 188 189 IFunctionTree t0 = importer.Import(@"(log (- (/ (variable 1.0b 0) 2.0)190 (* (variable 1.0 c 0) 2.0)))");191 IFunctionTree t1 = importer.Import(@"(* ( + (exp (variable 1.0 a 0))192 (* (variable 1.0 c 0) 2.0)) 2.0)");193 IFunctionTree t2 = importer.Import(@"( / (+ (exp (variable 1.0 a 0))194 (/ (variable 1.0 b 0) 2.0)) 2.0)");184 IFunctionTree tree = importer.Import(@"(open-- (flip (open-log (open-param 1.0 - 0))) 185 (flip (f1-* (open-param 2.0 - 0) 2.0)) 186 (flip (flip (f1-* (open-param 4.0 - 0) 2.0))))"); 187 188 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 189 190 IFunctionTree t0 = importer.Import(@"(log (- (/ (variable 0.5 b 0) 2.0) 191 (* (variable 4.0 c 0) 2.0)))"); 192 IFunctionTree t1 = importer.Import(@"(* (* (+ (exp (variable 1.0 a 0)) 193 (* (variable 4.0 c 0) 2.0)) 2.0) 2)"); 194 IFunctionTree t2 = importer.Import(@"(* (/ (+ (exp (variable 1.0 a 0)) 195 (/ (variable 0.5 b 0) 2.0)) 2.0) 0.25)"); 195 196 196 197 CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() { … … 203 204 (flip (f1-- 204 205 (flip (f1-/ 205 (open-param - 0) 4.0)) 3.0)) 2.0))206 (open-param - 0)207 (open-param - 0)))");206 (open-param 1.0 - 0) 4.0)) 3.0)) 2.0)) 207 (open-param 1.0 - 0) 208 (open-param 1.0 - 0)))"); 208 209 // -3*4-2 x 209 210 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 235 236 { 236 237 // expression with one parameter 237 IFunctionTree tree = importer.Import(@"(f1-* (open-param - 0) (variable 1.0 d 0))");238 IFunctionTree tree = importer.Import(@"(f1-* (open-param 1.0 - 0) (variable 1.0 d 0))"); 238 239 239 240 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 250 251 { 251 252 // expression with one parameter 252 IFunctionTree tree = importer.Import(@"(open-log (open-param - 0))");253 IFunctionTree tree = importer.Import(@"(open-log (open-param 1.0 - 0))"); 253 254 254 255 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 265 266 { 266 267 // expression with flip and one parameter 267 IFunctionTree tree = importer.Import(@"(flip (open-log (open-param - 0)))");268 IFunctionTree tree = importer.Import(@"(flip (open-log (open-param 1.0 - 0)))"); 268 269 269 270 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 281 282 { 282 283 // expression with flip and one parameter 283 IFunctionTree tree = importer.Import(@"(open-param - 0)");284 IFunctionTree tree = importer.Import(@"(open-param 1.0 - 0)"); 284 285 285 286 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 297 298 298 299 private void CompareTrees(List<IFunctionTree> actual, List<IFunctionTree> expected) { 299 var expectedEnumerator = expected.GetEnumerator(); 300 var expectedEnumerator = expected.GetEnumerator(); 300 301 foreach (var actualTree in actual) { 301 302 if (!expectedEnumerator.MoveNext()) Assert.Fail(); … … 312 313 var actualVar = (VariableFunctionTree)a.Current; 313 314 Assert.AreEqual(expectedVar.VariableName, actualVar.VariableName); 314 Assert. AreEqual(expectedVar.Weight, actualVar.Weight);315 Assert.IsTrue(expectedVar.Weight.IsAlmost(actualVar.Weight)); 315 316 Assert.AreEqual(expectedVar.SampleOffset, actualVar.SampleOffset); 316 317 } else if (e.Current.Function is Constant) { -
trunk/sources/HeuristicLab.GP.Tests/SymbolicExpressionImporter.cs
r2627 r2674 102 102 } else if (tokens.Peek().StringValue.StartsWith(DIFFSTART)) { 103 103 tree = ParseDifferential(tokens); 104 } else if (tokens.Peek().StringValue.StartsWith(OPENPARAMSTART)) {104 } else if (tokens.Peek().StringValue.StartsWith(OPENPARAMSTART)) { 105 105 tree = ParseOpenParameter(tokens); 106 106 } else { … … 123 123 Token tok = tokens.Dequeue(); 124 124 Debug.Assert(tok.StringValue == "open-param"); 125 HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree t = (HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree)openParam.GetTreeNode(); 125 HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree t = (HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree)openParam.GetTreeNode(); 126 t.Weight = tokens.Dequeue().DoubleValue; 126 127 t.VariableName = tokens.Dequeue().StringValue; 127 128 t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
Note: See TracChangeset
for help on using the changeset viewer.