Changeset 2211 for branches/GP-Refactoring-713/sources
- Timestamp:
- 07/29/09 19:07:21 (15 years ago)
- Location:
- branches/GP-Refactoring-713/sources
- Files:
-
- 1 deleted
- 21 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-Refactoring-713/sources/HeuristicLab.DataAnalysis/3.2/Dataset.cs
r2162 r2211 382 382 cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>(); 383 383 } 384 cachedValuesInvalidated = false; 384 385 } 385 386 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/IFunction.cs
r2210 r2211 33 33 void RemoveAllowedSubFunction(IFunction f, int index); 34 34 bool IsAllowedSubFunction(IFunction f, int index); 35 int Min Arity{ get; }36 int Max Arity{ get; }35 int MinSubTrees { get; } 36 int MaxSubTrees { get; } 37 37 int MinTreeHeight { get; } 38 38 int MinTreeSize { get; } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs
r2210 r2211 46 46 private const string VOTES = "Votes"; 47 47 private const string ACCURACY = "Accuracy"; 48 private const string TREEEVALUATOR = "TreeEvaluator"; 48 49 49 50 private const double EPSILON = 1E-6; … … 65 66 AddVariableInfo(new VariableInfo(BESTMODELLSCOPE, "The variable containing the scope of the model (incl. meta data)", typeof(IScope), VariableKind.In)); 66 67 AddVariableInfo(new VariableInfo(BESTMODELL, "The variable in the scope of the model that contains the actual model", typeof(IGeneticProgrammingModel), VariableKind.In)); 68 AddVariableInfo(new VariableInfo(TREEEVALUATOR, "The evaluator to apply to the function tree", typeof(ITreeEvaluator), VariableKind.In)); 67 69 AddVariableInfo(new VariableInfo(VOTES, "Array with the votes for each instance", typeof(IntMatrixData), VariableKind.New)); 68 70 AddVariableInfo(new VariableInfo(ACCURACY, "Accuracy of the one-vs-one multi-cass classifier", typeof(DoubleData), VariableKind.New)); … … 85 87 IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>(BESTMODELL, bestScope, true); 86 88 87 BakedTreeEvaluator evaluator = new BakedTreeEvaluator();89 ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>(TREEEVALUATOR, bestScope, true); 88 90 evaluator.PrepareForEvaluation(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0, gpModel.FunctionTree); 89 91 for(int i = 0; i < (samplesEnd - samplesStart); i++) { -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Addition.cs
r2202 r2211 42 42 : base() { 43 43 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 44 Min Arity= 2;45 Max Arity= 3;44 MinSubTrees = 2; 45 MaxSubTrees = 3; 46 46 } 47 47 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/And.cs
r2202 r2211 38 38 public And() 39 39 : base() { 40 Min Arity = 2; MaxArity= 3;40 MinSubTrees = 2; MaxSubTrees = 3; 41 41 } 42 42 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Average.cs
r2202 r2211 36 36 public Average() 37 37 : base() { 38 Min Arity = 2; MaxArity= 3;38 MinSubTrees = 2; MaxSubTrees = 3; 39 39 } 40 40 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ConstantFunctionTree.cs
r2210 r2211 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 30 public class ConstantFunctionTree : FunctionTreeBase { 31 private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly(); 31 32 public double Value { get; set; } 32 33 33 public ConstantFunctionTree(Constant constant) 34 : base(constant) {34 public ConstantFunctionTree(Constant constant) { 35 Function = constant; 35 36 } 36 37 37 protected ConstantFunctionTree(ConstantFunctionTree original) 38 : base(original) {38 protected ConstantFunctionTree(ConstantFunctionTree original) { 39 Function = original.Function; 39 40 Value = original.Value; 41 } 42 43 public override IList<IFunctionTree> SubTrees { 44 get { 45 return subTrees; 46 } 40 47 } 41 48 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs
r2210 r2211 238 238 239 239 private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) { 240 for (int i = 0; i < f.Max Arity; i++) {240 for (int i = 0; i < f.MaxSubTrees; i++) { 241 241 SetAllowedSubOperators(f, i, gs); 242 242 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HL3TreeEvaluator.cs
r2202 r2211 34 34 /// Not thread-safe! 35 35 /// </summary> 36 public class BakedTreeEvaluator : TreeEvaluatorBase {36 public class HL3TreeEvaluator : TreeEvaluatorBase { 37 37 38 38 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj
r2210 r2211 85 85 <Compile Include="And.cs" /> 86 86 <Compile Include="Average.cs" /> 87 <Compile Include="BakedTreeEvaluator.cs" />88 87 <Compile Include="Constant.cs" /> 89 88 <Compile Include="AlgorithmBase.cs" /> 90 89 <Compile Include="ConstantFunctionTree.cs" /> 91 90 <Compile Include="Evaluators\SimpleGPEvaluatorBase.cs" /> 91 <Compile Include="HL3TreeEvaluator.cs" /> 92 92 <Compile Include="VariableFunctionTree.cs" /> 93 93 <Compile Include="TreeEvaluatorBase.cs" /> -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/IfThenElse.cs
r2202 r2211 38 38 public IfThenElse() 39 39 : base() { 40 Min Arity = 3; MaxArity= 3;40 MinSubTrees = 3; MaxSubTrees = 3; 41 41 } 42 42 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Multiplication.cs
r2202 r2211 43 43 : base() { 44 44 // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze) 45 Min Arity = 2; MaxArity= 3;45 MinSubTrees = 2; MaxSubTrees = 3; 46 46 } 47 47 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Or.cs
r2202 r2211 37 37 public Or() 38 38 : base() { 39 Min Arity = 2; MaxArity= 3;39 MinSubTrees = 2; MaxSubTrees = 3; 40 40 } 41 41 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/VariableFunctionTree.cs
r2210 r2211 29 29 namespace HeuristicLab.GP.StructureIdentification { 30 30 public class VariableFunctionTree : FunctionTreeBase { 31 private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly(); 31 32 public double Weight { get; set; } 32 33 public string VariableName { get; set; } 33 34 public int SampleOffset { get; set; } 34 35 35 public VariableFunctionTree(Variable variable) 36 : base(variable) {36 public VariableFunctionTree(Variable variable) { 37 Function = variable; 37 38 } 38 39 39 protected VariableFunctionTree(VariableFunctionTree original) 40 : base(original) {40 protected VariableFunctionTree(VariableFunctionTree original) { 41 Function = original.Function; 41 42 Weight = original.Weight; 42 43 VariableName = original.VariableName; 43 44 SampleOffset = original.SampleOffset; 45 } 46 47 public override IList<IFunctionTree> SubTrees { 48 get { 49 return subTrees; 50 } 44 51 } 45 52 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs
r2210 r2211 30 30 public BinaryFunction() 31 31 : base() { 32 Min Arity = 2; MaxArity= 2;32 MinSubTrees = 2; MaxSubTrees = 2; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs
r2210 r2211 49 49 } 50 50 51 public int Min Arity{51 public int MinSubTrees { 52 52 get { 53 53 return minArity; … … 59 59 } 60 60 61 public int Max Arity{61 public int MaxSubTrees { 62 62 get { 63 63 return maxArity; … … 128 128 129 129 public ICollection<IFunction> GetAllowedSubFunctions(int index) { 130 if (index < 0 || index > Max Arity) throw new ArgumentException("Index outside of allowed range. index = " + index);130 if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index); 131 131 //if (allowedSubFunctions == null) { 132 132 // // first time: analyze the constraint and create a cached copy of the allowed sub-functions … … 140 140 141 141 public void AddAllowedSubFunction(IFunction function, int index) { 142 if (index < 0 || index > Max Arity) throw new ArgumentException("Index outside of allowed range. index = " + index);142 if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index); 143 143 if (allowedSubFunctions[index] == null) { 144 144 allowedSubFunctions[index] = new List<IFunction>(); … … 150 150 151 151 public void RemoveAllowedSubFunction(IFunction function, int index) { 152 if (index < 0 || index > Max Arity) throw new ArgumentException("Index outside of allowed range. index = " + index);152 if (index < 0 || index > MaxSubTrees) throw new ArgumentException("Index outside of allowed range. index = " + index); 153 153 allowedSubFunctions[index].Add(function); 154 154 } … … 190 190 int sum = 1; 191 191 int minSize = int.MaxValue; 192 for (int i = 0; i < Min Arity; i++) {192 for (int i = 0; i < MinSubTrees; i++) { 193 193 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 194 194 minSize = Math.Min(minSize, subFun.MinTreeSize); … … 203 203 int height = 0; 204 204 int minHeight = int.MaxValue; 205 for (int i = 0; i < Min Arity; i++) {205 for (int i = 0; i < MinSubTrees; i++) { 206 206 foreach (IFunction subFun in GetAllowedSubFunctions(i)) { 207 207 minHeight = Math.Min(minHeight, subFun.MinTreeHeight); -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs
r2210 r2211 31 31 private IFunction function; 32 32 33 public FunctionTreeBase() { 34 } 35 33 36 public FunctionTreeBase(IFunction function) { 34 37 subTrees = new List<IFunctionTree>(); … … 49 52 } 50 53 51 public IList<IFunctionTree> SubTrees {54 public virtual IList<IFunctionTree> SubTrees { 52 55 get { return subTrees; } 53 56 } … … 55 58 public IFunction Function { 56 59 get { return function; } 60 protected set { 61 function = value; 62 } 57 63 } 58 64 59 65 public int GetSize() { 60 66 int size = 1; 61 foreach (IFunctionTree tree in subTrees) size += tree.GetSize();67 foreach (IFunctionTree tree in SubTrees) size += tree.GetSize(); 62 68 return size; 63 69 } … … 65 71 public int GetHeight() { 66 72 int maxHeight = 0; 67 foreach (IFunctionTree tree in subTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight());73 foreach (IFunctionTree tree in SubTrees) maxHeight = Math.Max(maxHeight, tree.GetHeight()); 68 74 return maxHeight + 1; 69 75 } … … 78 84 79 85 public void AddSubTree(IFunctionTree tree) { 80 subTrees.Add(tree);86 SubTrees.Add(tree); 81 87 } 82 88 83 public v oid InsertSubTree(int index, IFunctionTree tree) {84 subTrees.Insert(index, tree);89 public virtual void InsertSubTree(int index, IFunctionTree tree) { 90 SubTrees.Insert(index, tree); 85 91 } 86 92 87 public v oid RemoveSubTree(int index) {88 subTrees.RemoveAt(index);93 public virtual void RemoveSubTree(int index) { 94 SubTrees.RemoveAt(index); 89 95 } 90 96 -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs
r2210 r2211 30 30 public Terminal() 31 31 : base() { 32 Min Arity = 0; MaxArity= 0;32 MinSubTrees = 0; MaxSubTrees = 0; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs
r2210 r2211 30 30 public UnaryFunction() 31 31 : base() { 32 Min Arity = 1; MaxArity= 1;32 MinSubTrees = 1; MaxSubTrees = 1; 33 33 } 34 34 } -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/ChangeNodeTypeManipulation.cs
r2210 r2211 136 136 IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)]; 137 137 // arity of the selected operator 138 int minArity = selectedFunction.Min Arity;139 int maxArity = selectedFunction.Max Arity;138 int minArity = selectedFunction.MinSubTrees; 139 int maxArity = selectedFunction.MaxSubTrees; 140 140 // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible 141 141 if (actualArity > maxArity) -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/DeleteSubTreeManipulation.cs
r2210 r2211 59 59 // select a branch to prune 60 60 int childIndex = random.Next(parent.SubTrees.Count); 61 if (parent.SubTrees.Count > parent.Function.Min Arity) {61 if (parent.SubTrees.Count > parent.Function.MinSubTrees) { 62 62 parent.RemoveSubTree(childIndex); 63 63 // actually since the next sub-trees are shifted in the place of the removed branch -
branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/TreeGardener.cs
r2210 r2211 59 59 // init functions and terminals based on constraints 60 60 foreach(IFunction fun in funLibrary.Functions) { 61 if(fun.Max Arity== 0) {61 if(fun.MaxSubTrees == 0) { 62 62 terminals.Add(fun); 63 63 allFunctions.Add(fun); … … 107 107 int currentSize = 1; 108 108 int totalListMinSize = 0; 109 int minArity = root.Function.Min Arity;110 int maxArity = root.Function.Max Arity;109 int minArity = root.Function.MinSubTrees; 110 int maxArity = root.Function.MaxSubTrees; 111 111 if (maxArity >= size) { 112 112 maxArity = size; … … 142 142 totalListMinSize--; 143 143 144 minArity = selectedFunction.Min Arity;145 maxArity = selectedFunction.Max Arity;144 minArity = selectedFunction.MinSubTrees; 145 maxArity = selectedFunction.MaxSubTrees; 146 146 if (maxArity >= size) { 147 147 maxArity = size; … … 277 277 } 278 278 279 if(tree.SubTrees.Count < tree.Function.Min Arity || tree.SubTrees.Count > tree.Function.MaxArity)279 if(tree.SubTrees.Count < tree.Function.MinSubTrees || tree.SubTrees.Count > tree.Function.MaxSubTrees) 280 280 return false; 281 281 foreach(IFunctionTree subTree in tree.SubTrees) { … … 306 306 307 307 private bool IsPossibleParent(IFunction f, List<IFunction> children) { 308 int minArity = f.Min Arity;309 int maxArity = f.Max Arity;308 int minArity = f.MinSubTrees; 309 int maxArity = f.MaxSubTrees; 310 310 // note: we can't assume that the operators in the children list have different types! 311 311 … … 370 370 } 371 371 internal static bool IsTerminal(IFunction f) { 372 return f.Min Arity == 0 && f.MaxArity== 0;372 return f.MinSubTrees == 0 && f.MaxSubTrees == 0; 373 373 } 374 374 internal ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) { … … 397 397 private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) { 398 398 if(maxTreeHeight == 0) return parent.GetTreeNode(); 399 int minArity = parent.Min Arity;400 int maxArity = parent.Max Arity;399 int minArity = parent.MinSubTrees; 400 int maxArity = parent.MaxSubTrees; 401 401 int actualArity = random.Next(minArity, maxArity + 1); 402 402 if(actualArity > 0) { … … 418 418 private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) { 419 419 if(maxTreeHeight == 0) return parent.GetTreeNode(); 420 int minArity = parent.Min Arity;421 int maxArity = parent.Max Arity;420 int minArity = parent.MinSubTrees; 421 int maxArity = parent.MaxSubTrees; 422 422 int actualArity = random.Next(minArity, maxArity + 1); 423 423 if(actualArity > 0) {
Note: See TracChangeset
for help on using the changeset viewer.