Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2455


Ignore:
Timestamp:
10/29/09 18:10:07 (15 years ago)
Author:
gkronber
Message:

Added test for ProbabilisticTreeCreator. #791 (Tests for GP operators and structure identification evaluators)

Location:
trunk/sources/HeuristicLab.GP.Tests
Files:
2 edited

Legend:

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

    r2447 r2455  
    6868        strBuilder.Append(Environment.NewLine);
    6969        strBuilder.Append("< "); strBuilder.Append((i + 1) * 5);
    70         strBuilder.Append(": "); strBuilder.Append(histogram[i]);
     70        strBuilder.Append(": "); strBuilder.AppendFormat("{0:#0.00%}", histogram[i] / (double)randomTrees.Length);
    7171      }
    7272      Assert.Inconclusive("Size distribution of ProbabilisticTreeCreator: " + strBuilder);
     
    7676    public void FunctionDistributionTest() {
    7777      Dictionary<IFunction, int> occurances = new Dictionary<IFunction, int>();
     78      double n = 0.0;
    7879      for (int i = 0; i < randomTrees.Length; i++) {
    7980        foreach (var node in FunctionTreeIterator.IteratePrefix(randomTrees[i])) {
     
    8283              occurances[node.Function] = 0;
    8384            occurances[node.Function]++;
     85            n++;
    8486          }
    8587        }
     
    8991        strBuilder.Append(Environment.NewLine);
    9092        strBuilder.Append(function.Name); strBuilder.Append(": ");
    91         strBuilder.Append(occurances[function]);
     93        strBuilder.AppendFormat("{0:#0.00%}", occurances[function] / n);
    9294      }
    9395      Assert.Inconclusive("Function distribution of ProbabilisticTreeCreator: " + strBuilder);
     
    9597
    9698    [TestMethod()]
     99    public void NumberOfSubTreesDistributionTest() {
     100      Dictionary<int, int> occurances = new Dictionary<int, int>();
     101      double n = 0.0;
     102      for (int i = 0; i < randomTrees.Length; i++) {
     103        foreach (var node in FunctionTreeIterator.IteratePrefix(randomTrees[i])) {
     104          if (!occurances.ContainsKey(node.SubTrees.Count))
     105            occurances[node.SubTrees.Count] = 0;
     106          occurances[node.SubTrees.Count]++;
     107          n++;
     108        }
     109      }
     110      StringBuilder strBuilder = new StringBuilder();
     111      foreach (var arity in occurances.Keys) {
     112        strBuilder.Append(Environment.NewLine);
     113        strBuilder.Append(arity); strBuilder.Append(": ");
     114        strBuilder.AppendFormat("{0:#0.00%}", occurances[arity] / n);
     115      }
     116      Assert.Inconclusive("Distribution of function arities of ProbabilisticTreeCreator: " + strBuilder);
     117    }
     118
     119
     120    [TestMethod()]
    97121    public void TerminalDistributionTest() {
    98122      Dictionary<IFunction, int> occurances = new Dictionary<IFunction, int>();
     123      double n = 0.0;
    99124      for (int i = 0; i < randomTrees.Length; i++) {
    100125        foreach (var node in FunctionTreeIterator.IteratePrefix(randomTrees[i])) {
     
    103128              occurances[node.Function] = 0;
    104129            occurances[node.Function]++;
     130            n++;
    105131          }
    106132        }
     
    110136        strBuilder.Append(Environment.NewLine);
    111137        strBuilder.Append(function.Name); strBuilder.Append(": ");
    112         strBuilder.Append(occurances[function]);
     138        strBuilder.AppendFormat("{0:#0.00%}", occurances[function] / n);
    113139      }
    114140      Assert.Inconclusive("Terminal distribution of ProbabilisticTreeCreator: " + strBuilder);
  • trunk/sources/HeuristicLab.GP.Tests/Util.cs

    r2447 r2455  
    9090      doubleFunctions.Add(constant);
    9191      doubleFunctions.Add(addition);
    92       //doubleFunctions.Add(average);
     92      // doubleFunctions.Add(average);
    9393      doubleFunctions.Add(cosinus);
    9494      doubleFunctions.Add(division);
     
    132132      functionLibrary.AddFunction(constant);
    133133      functionLibrary.AddFunction(addition);
    134       //functionLibrary.AddFunction(average);
     134      // functionLibrary.AddFunction(average);
    135135      functionLibrary.AddFunction(and);
    136136      functionLibrary.AddFunction(cosinus);
Note: See TracChangeset for help on using the changeset viewer.