Changeset 286 for trunk/sources/HeuristicLab.StructureIdentification
- Timestamp:
- 06/03/08 16:21:56 (17 years ago)
- 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 48 48 </ItemGroup> 49 49 <ItemGroup> 50 <Compile Include="ProbabilisticTreeCreator.cs" /> 50 51 <Compile Include="Evaluation\CoefficientOfDeterminationEvaluator.cs" /> 51 52 <Compile Include="Evaluation\MCCEvaluator.cs" /> -
trunk/sources/HeuristicLab.StructureIdentification/RampedTreeCreator.cs
r285 r286 29 29 30 30 namespace HeuristicLab.StructureIdentification { 31 public class Ra ndomTreeCreator : OperatorBase {31 public class RampedTreeCreator : OperatorBase { 32 32 public override string Description { 33 33 get { return @"Generates a new random operator tree."; } 34 34 } 35 35 36 public Ra ndomTreeCreator()36 public RampedTreeCreator() 37 37 : base() { 38 38 AddVariableInfo(new VariableInfo("Random", "Uniform random number generator", typeof(MersenneTwister), VariableKind.In)); -
trunk/sources/HeuristicLab.StructureIdentification/TreeGardener.cs
r284 r286 97 97 IFunctionTree tree = MakeUnbalancedTree(rootFunction, maxTreeSize - 1, maxTreeHeight - 1); 98 98 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; 99 160 } 100 161
Note: See TracChangeset
for help on using the changeset viewer.