Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/03/08 16:21:56 (17 years ago)
Author:
gkronber
Message:
  • renamed RandomTreeCreator to RampedTreeCreator
  • added ProbabilisticTreeCreator and method to create trees with a more uniform size distribution (actual distribution still depends on the arity of functions in the function library)
Location:
trunk/sources/HeuristicLab.StructureIdentification
Files:
1 added
2 edited
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/HeuristicLab.StructureIdentification.csproj

    r169 r286  
    4848  </ItemGroup>
    4949  <ItemGroup>
     50    <Compile Include="ProbabilisticTreeCreator.cs" />
    5051    <Compile Include="Evaluation\CoefficientOfDeterminationEvaluator.cs" />
    5152    <Compile Include="Evaluation\MCCEvaluator.cs" />
  • trunk/sources/HeuristicLab.StructureIdentification/RampedTreeCreator.cs

    r285 r286  
    2929
    3030namespace HeuristicLab.StructureIdentification {
    31   public class RandomTreeCreator : OperatorBase {
     31  public class RampedTreeCreator : OperatorBase {
    3232    public override string Description {
    3333      get { return @"Generates a new random operator tree."; }
    3434    }
    3535
    36     public RandomTreeCreator()
     36    public RampedTreeCreator()
    3737      : base() {
    3838      AddVariableInfo(new VariableInfo("Random", "Uniform random number generator", typeof(MersenneTwister), VariableKind.In));
  • trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs

    r284 r286  
    9797      IFunctionTree tree = MakeUnbalancedTree(rootFunction, maxTreeSize - 1, maxTreeHeight - 1);
    9898      return tree;
     99    }
     100
     101    internal IFunctionTree PTC2(IRandom random, int size, int maxDepth) {
     102      if(size == 1) return RandomSelect(terminals).GetTreeNode();
     103      List<object[]> list = new List<object[]>();
     104      IFunctionTree root = GetRandomRoot(size, maxDepth).GetTreeNode();
     105      int currentSize = 1;
     106      int minArity;
     107      int maxArity;
     108      GetMinMaxArity(root.Function, out minArity, out maxArity);
     109      if(maxArity >= size) {
     110        maxArity = size;
     111      }
     112      int actualArity = random.Next(minArity, maxArity + 1);
     113      for(int i=0;i<actualArity;i++) {
     114        // insert a dummy sub-tree and add the pending extension to the list
     115        root.AddSubTree(null);
     116        list.Add(new object[] {root, i, 2});
     117      }
     118
     119      while(list.Count > 0 && list.Count + currentSize < size) {
     120        int randomIndex = random.Next(list.Count);
     121        object[] nextExtension = list[randomIndex];
     122        list.RemoveAt(randomIndex);
     123        IFunctionTree parent = (IFunctionTree)nextExtension[0];
     124        int a = (int)nextExtension[1];
     125        int d = (int)nextExtension[2];
     126        if(d == maxDepth) {
     127          parent.RemoveSubTree(a);
     128          parent.InsertSubTree(a, RandomSelect(terminals).GetTreeNode());
     129        } else {
     130          IFunction selectedFunction = RandomSelect(functions);
     131          IFunctionTree newTree = selectedFunction.GetTreeNode();
     132          parent.RemoveSubTree(a);
     133          parent.InsertSubTree(a, newTree);
     134
     135          GetMinMaxArity(selectedFunction, out minArity, out maxArity);
     136          if(maxArity >= size) {
     137            maxArity = size;
     138          }
     139          actualArity = random.Next(minArity, maxArity + 1);
     140          for(int i = 0; i < actualArity; i++) {
     141            // insert a dummy sub-tree and add the pending extension to the list
     142            newTree.AddSubTree(null);
     143            list.Add(new object[] { newTree, i, d + 1 });
     144          }
     145        }
     146        currentSize++;
     147      }
     148      while(list.Count > 0) {
     149        int randomIndex = random.Next(list.Count);
     150        object[] nextExtension = list[randomIndex];
     151        list.RemoveAt(randomIndex);
     152        IFunctionTree parent = (IFunctionTree)nextExtension[0];
     153        int a = (int)nextExtension[1];
     154        int d = (int)nextExtension[2];
     155        IFunction selectedTerminal = RandomSelect(terminals);
     156        parent.RemoveSubTree(a);
     157        parent.InsertSubTree(a, selectedTerminal.GetTreeNode());
     158      }
     159      return root;
    99160    }
    100161
Note: See TracChangeset for help on using the changeset viewer.