Changeset 2633 for trunk/sources
- Timestamp:
- 01/18/10 09:28:53 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs
r2631 r2633 58 58 exprScope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("FunctionTree"), new GeneticProgrammingModel(transformedTree))); 59 59 exprScope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName("TargetVariable"), new StringData(targetVariableEnumerator.Current))); 60 Debug.Assert(!(transformedTree is VariableFunctionTree) || ((VariableFunctionTree)transformedTree).VariableName != targetVariableEnumerator.Current); 60 61 } 61 62 … … 214 215 /// <returns></returns> 215 216 private static IFunctionTree TransformExpression(IFunctionTree tree, string targetVariable, IEnumerable<string> parameters) { 216 if (tree.Function is Variable || tree.Function is Constant || tree.Function is Differential) return tree; 217 if (tree.Function is Constant) return tree; 218 if (tree.Function is Variable || tree.Function is Differential) { 219 VariableFunctionTree varTree = (VariableFunctionTree)tree; 220 varTree.Weight = 1.0; 221 if (varTree.VariableName == targetVariable) varTree.VariableName = parameters.First(); 222 return varTree; 223 } 217 224 if (tree.Function is Addition || tree.Function is Subtraction || 218 225 tree.Function is Multiplication || tree.Function is Division || -
trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs
r2627 r2633 235 235 { 236 236 // expression with one parameter 237 IFunctionTree tree = importer.Import(@"(f1-* ( variable 1.0 a0) (variable 1.0 d 0))");237 IFunctionTree tree = importer.Import(@"(f1-* (open-param - 0) (variable 1.0 d 0))"); 238 238 239 239 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 250 250 { 251 251 // expression with one parameter 252 IFunctionTree tree = importer.Import(@"(open-log ( variable 1.0 a0))");252 IFunctionTree tree = importer.Import(@"(open-log (open-param - 0))"); 253 253 254 254 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 265 265 { 266 266 // expression with flip and one parameter 267 IFunctionTree tree = importer.Import(@"(flip (open-log ( variable 1.0 a0)))");267 IFunctionTree tree = importer.Import(@"(flip (open-log (open-param - 0)))"); 268 268 269 269 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); … … 272 272 IFunctionTree t1 = importer.Import("(exp (variable 1.0 a 0))"); 273 273 IFunctionTree t2 = importer.Import("(exp (variable 1.0 a 0))"); 274 275 276 CompareTrees(actualTrees, new List<IFunctionTree>() { 277 t0, t1, t2 278 }); 279 } 280 281 { 282 // expression with flip and one parameter 283 IFunctionTree tree = importer.Import(@"(open-param - 0)"); 284 285 IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" }); 286 287 IFunctionTree t0 = importer.Import("(variable 1.0 b 0)"); 288 IFunctionTree t1 = importer.Import("(variable 1.0 a 0)"); 289 IFunctionTree t2 = importer.Import("(variable 1.0 a 0)"); 274 290 275 291
Note: See TracChangeset
for help on using the changeset viewer.