Free cookie consent management tool by TermsFeed Policy Generator

Changeset 23


Ignore:
Timestamp:
02/21/08 11:45:52 (16 years ago)
Author:
gkronber
Message:

changed boolean variable BalanceTrees to double BalancedTreesRate (ticket #11)

Location:
trunk/sources/HeuristicLab.StructureIdentification
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/ChangeNodeTypeManipulation.cs

    r2 r23  
    3838      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    3939      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    40       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
     40      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    4141      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    4242      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
     
    4949      MersenneTwister random = GetVariableValue<MersenneTwister>("Random", scope, true);
    5050      GPOperatorLibrary library = GetVariableValue<GPOperatorLibrary>("OperatorLibrary", scope, true);
    51       bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;
     51      double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;
    5252      IntData treeSize = GetVariableValue<IntData>("TreeSize", scope, false);
    5353      IntData treeHeight = GetVariableValue<IntData>("TreeHeight", scope, false);
     
    8787      } else {
    8888        List<IOperator> uninitializedOperators;
    89         IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balanceTrees, out uninitializedOperators);
     89        IOperator newFunction = ChangeFunctionType(parent, selectedChild, selectedChildIndex, gardener, random, balancedTreesRate, out uninitializedOperators);
    9090
    9191        if (parent == null) {
     
    139139
    140140    private IOperator ChangeFunctionType(IOperator parent, IOperator child, int childIndex, TreeGardener gardener, MersenneTwister random,
    141       bool balanceTrees, out List<IOperator> uninitializedOperators) {
     141      double balancedTreesRate, out List<IOperator> uninitializedOperators) {
    142142      // since there are suboperators, we have to check which
    143143      // and how many of the existing suboperators we can reuse
     
    197197          availableSubOperators.Remove(selectedSubOperator); // the operator shouldn't be available for the following slots
    198198        } else {
    199           IOperator freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, balanceTrees);
     199          IOperator freshOperatorTree;
     200          if(random.NextDouble() <= balancedTreesRate) {
     201            freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true);
     202          } else {
     203            freshOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false);
     204          }
    200205          freshSubTrees.AddRange(gardener.GetAllOperators(freshOperatorTree));
    201206
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/CutOutNodeManipulation.cs

    r2 r23  
    5252      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    5353      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    54       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
     54      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    5555      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    5656      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
     
    6565      int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data;
    6666      int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data;
    67       bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;
     67      double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;
    6868
    6969      TreeGardener gardener = new TreeGardener(random, library);
     
    9595        } else {
    9696          // create a new random tree
    97           IOperator newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, balanceTrees);
     97          IOperator newOperator;
     98          if(random.NextDouble() <= balancedTreesRate) {
     99            newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, true);
     100          } else {
     101            newOperator = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, false);
     102          }
    98103
    99104          GetVariableValue<IntData>("TreeSize", scope, true).Data = gardener.GetTreeSize(newOperator);
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/DeleteSubTreeManipulation.cs

    r2 r23  
    4242      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    4343      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    44       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
    4544      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In | VariableKind.Out));
    4645      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In | VariableKind.Out));
  • trunk/sources/HeuristicLab.StructureIdentification/Manipulation/SubstituteSubTreeManipulation.cs

    r2 r23  
    4141      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    4242      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    43       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
     43      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    4444      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to manipulate", typeof(IOperator), VariableKind.In));
    4545      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
     
    5454      int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data;
    5555      int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data;
    56       bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;
     56      double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;
    5757      int treeSize = GetVariableValue<IntData>("TreeSize", scope, true).Data;
    5858      int treeHeight = GetVariableValue<IntData>("TreeHeight", scope, true).Data;
     
    6666
    6767        // create a new random operator tree
    68         IOperator newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, balanceTrees);
     68
     69        IOperator newOperatorTree;
     70        if(random.NextDouble() <= balancedTreesRate) {
     71          newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, true);
     72        } else {
     73          newOperatorTree = gardener.CreateRandomTree(gardener.AllOperators, maxTreeSize, maxTreeHeight, false);
     74        }
    6975
    7076        if(!gardener.IsValidTree(newOperatorTree)) {
     
    100106
    101107        // get a random operatorTree
    102         IOperator newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, balanceTrees);
     108        IOperator newOperatorTree;
     109        if(random.NextDouble() <= balancedTreesRate) {
     110          newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, true);
     111        } else {
     112          newOperatorTree = gardener.CreateRandomTree(allowedOperators, maxSubTreeSize, maxSubTreeHeight, false);
     113        }
    103114
    104115        IOperator oldChild = parent.SubOperators[childIndex];
  • trunk/sources/HeuristicLab.StructureIdentification/RandomTreeCreator.cs

    r2 r23  
    3939      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    4040      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    41       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
     41      AddVariableInfo(new VariableInfo("BalancedTreesRate", "Determines how many trees should be balanced", typeof(DoubleData), VariableKind.In));
    4242      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    4343      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
     
    5050      int maxTreeHeight = GetVariableValue<IntData>("MaxTreeHeight", scope, true).Data;
    5151      int maxTreeSize = GetVariableValue<IntData>("MaxTreeSize", scope, true).Data;
    52       bool balanceTrees = GetVariableValue<BoolData>("BalanceTrees", scope, true).Data;
     52      double balancedTreesRate = GetVariableValue<DoubleData>("BalancedTreesRate", scope, true).Data;
    5353
    5454      TreeGardener gardener = new TreeGardener(random, opLibrary);
     
    5656      int treeHeight = random.Next(1, maxTreeHeight + 1);
    5757      int treeSize = random.Next(1, maxTreeSize + 1);
    58 
    59       IOperator rootOperator = gardener.CreateRandomTree(treeSize, treeHeight, balanceTrees);
     58      IOperator rootOperator;
     59      if(random.NextDouble() <= balancedTreesRate) {
     60        rootOperator = gardener.CreateRandomTree(treeSize, treeHeight, true);
     61      } else {
     62        rootOperator = gardener.CreateRandomTree(treeSize, treeHeight, false);
     63      }
    6064
    6165      int actualTreeSize = gardener.GetTreeSize(rootOperator);
  • trunk/sources/HeuristicLab.StructureIdentification/Recombination/SinglePointCrossOver.cs

    r2 r23  
    4444      AddVariableInfo(new VariableInfo("MaxTreeHeight", "The maximal allowed height of the tree", typeof(IntData), VariableKind.In));
    4545      AddVariableInfo(new VariableInfo("MaxTreeSize", "The maximal allowed size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
    46       AddVariableInfo(new VariableInfo("BalanceTrees", "Determines if the trees should be balanced", typeof(BoolData), VariableKind.In));
    4746      AddVariableInfo(new VariableInfo("OperatorTree", "The tree to mutate", typeof(IOperator), VariableKind.In));
    4847      AddVariableInfo(new VariableInfo("TreeSize", "The size (number of nodes) of the tree", typeof(IntData), VariableKind.In));
  • trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs

    r2 r23  
    9696    internal IOperator CreateRandomTree(int maxTreeSize, int maxTreeHeight, bool balanceTrees) {
    9797      if (balanceTrees) {
    98         if (maxTreeHeight == 1) {
     98        if (maxTreeHeight == 1 || maxTreeSize==1) {
    9999          IOperator selectedTerminal = (IOperator)terminals[random.Next(terminals.Count())].Clone();
    100100          return selectedTerminal;
Note: See TracChangeset for help on using the changeset viewer.