Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/14/10 19:42:10 (15 years ago)
Author:
gkronber
Message:

Added test cases for network transformation and fixed bugs in network transformation operator. #833

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs

    r2625 r2627  
    66using System.Linq;
    77using System.Collections.Generic;
     8using HeuristicLab.Random;
     9using HeuristicLab.DataAnalysis;
    810
    911namespace HeuristicLab.GP.Test {
     
    197199      }
    198200      {
    199         IFunctionTree tree = importer.Import(@"(cycle (open-+
    200                                                          (flip (f1-+
    201                                                            (flip (f1--
    202                                                              (flip (f1-/
    203                                                                (open-param - 0) 4.0)) 3.0)) 2.0))
    204                                                          (open-param - 0)
    205                                                          (open-param - 0)))");
     201        IFunctionTree tree = importer.Import(@"(open-+
     202                                                 (flip (f1-+
     203                                                   (flip (f1--
     204                                                     (flip (f1-/
     205                                                       (open-param - 0) 4.0)) 3.0)) 2.0))
     206                                                 (open-param - 0)
     207                                                 (open-param - 0)))");
    206208        // -3*4-2 x
    207209        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
    208210
    209         IFunctionTree t0 = importer.Import("(+ (/ (- (+ (variable 1.0 b 0) (variable 1.0 c 0)) 3.0) 4.0) 2.0)");
     211        IFunctionTree t0 = importer.Import("(+ (/ (+ (+ (variable 1.0 b 0) (variable 1.0 c 0)) 3.0) 4.0) 2.0)");
    210212        IFunctionTree t1 = importer.Import("(- (- (* (- (variable 1.0 a 0) 2.0) 4.0) 3.0) (variable 1.0 c 0))");
    211213        IFunctionTree t2 = importer.Import("(- (- (* (- (variable 1.0 a 0) 2.0) 4.0) 3.0) (variable 1.0 b 0))");
     
    216218      });
    217219      }
    218 
     220      {
     221        // constant expression
     222        IFunctionTree tree = importer.Import(@"(* (variable 1.0 d 0) (variable 1.0 d 0))");
     223
     224        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
     225
     226        IFunctionTree t0 = importer.Import("(* (variable 1.0 d 0) (variable 1.0 d 0))");
     227        IFunctionTree t1 = importer.Import("(* (variable 1.0 d 0) (variable 1.0 d 0))");
     228        IFunctionTree t2 = importer.Import("(* (variable 1.0 d 0) (variable 1.0 d 0))");
     229
     230
     231        CompareTrees(actualTrees, new List<IFunctionTree>() {
     232        t0, t1, t2
     233        });
     234      }
     235      {
     236        // expression with one parameter
     237        IFunctionTree tree = importer.Import(@"(f1-* (variable 1.0 a 0) (variable 1.0 d 0))");
     238
     239        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
     240
     241        IFunctionTree t0 = importer.Import("(/ (variable 1.0 b 0) (variable 1.0 d 0))");
     242        IFunctionTree t1 = importer.Import("(* (variable 1.0 a 0) (variable 1.0 d 0))");
     243        IFunctionTree t2 = importer.Import("(* (variable 1.0 a 0) (variable 1.0 d 0))");
     244
     245
     246        CompareTrees(actualTrees, new List<IFunctionTree>() {
     247        t0, t1, t2
     248        });
     249      }
     250      {
     251        // expression with one parameter
     252        IFunctionTree tree = importer.Import(@"(open-log (variable 1.0 a 0))");
     253
     254        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
     255
     256        IFunctionTree t0 = importer.Import("(exp (variable 1.0 b 0))");
     257        IFunctionTree t1 = importer.Import("(log (variable 1.0 a 0))");
     258        IFunctionTree t2 = importer.Import("(log (variable 1.0 a 0))");
     259
     260
     261        CompareTrees(actualTrees, new List<IFunctionTree>() {
     262        t0, t1, t2
     263        });
     264      }
     265      {
     266        // expression with flip and one parameter
     267        IFunctionTree tree = importer.Import(@"(flip (open-log (variable 1.0 a 0)))");
     268
     269        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
     270
     271        IFunctionTree t0 = importer.Import("(log (variable 1.0 b 0))");
     272        IFunctionTree t1 = importer.Import("(exp (variable 1.0 a 0))");
     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      }
    219280    }
    220281
     
    245306      }
    246307    }
     308
     309    [TestMethod()]
     310    [DeploymentItem("HeuristicLab.GP.StructureIdentification.Networks-3.2.dll")]
     311    public void TransformRandomTreesTest() {
     312
     313      MersenneTwister twister = new MersenneTwister();
     314      Dataset ds = Util.CreateRandomDataset(twister, 1, 20);
     315      IFunctionTree[] randomTrees = Util.CreateRandomTrees(twister, ds, FunctionLibraryInjector.Create(false, 0, 0), 1000, 1, 100);
     316      foreach (var tree in randomTrees) {
     317        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
     318        actualTrees.ToList();
     319      }
     320    }
    247321  }
    248322}
Note: See TracChangeset for help on using the changeset viewer.