Free cookie consent management tool by TermsFeed Policy Generator

Changeset 2211


Ignore:
Timestamp:
07/29/09 19:07:21 (15 years ago)
Author:
gkronber
Message:

#713

  • renamed MinArity and MaxArity properties
  • fixed a caching bug in the Dataset
  • renamed BakedTreeEvaluator to HL3TreeEvaluator
  • deleted class BakedFunctionTree
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  
    382382        cachedRanges[i] = new Dictionary<int, Dictionary<int, double>>();
    383383      }
     384      cachedValuesInvalidated = false;
    384385    }
    385386  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.Interfaces/3.3/IFunction.cs

    r2210 r2211  
    3333    void RemoveAllowedSubFunction(IFunction f, int index);
    3434    bool IsAllowedSubFunction(IFunction f, int index);
    35     int MinArity { get; }
    36     int MaxArity { get; }
     35    int MinSubTrees { get; }
     36    int MaxSubTrees { get; }
    3737    int MinTreeHeight { get; }
    3838    int MinTreeSize { get; }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification.Classification/3.3/MulticlassOneVsOneAnalyzer.cs

    r2210 r2211  
    4646    private const string VOTES = "Votes";
    4747    private const string ACCURACY = "Accuracy";
     48    private const string TREEEVALUATOR = "TreeEvaluator";
    4849
    4950    private const double EPSILON = 1E-6;
     
    6566      AddVariableInfo(new VariableInfo(BESTMODELLSCOPE, "The variable containing the scope of the model (incl. meta data)", typeof(IScope), VariableKind.In));
    6667      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));
    6769      AddVariableInfo(new VariableInfo(VOTES, "Array with the votes for each instance", typeof(IntMatrixData), VariableKind.New));
    6870      AddVariableInfo(new VariableInfo(ACCURACY, "Accuracy of the one-vs-one multi-cass classifier", typeof(DoubleData), VariableKind.New));
     
    8587        IGeneticProgrammingModel gpModel = GetVariableValue<IGeneticProgrammingModel>(BESTMODELL, bestScope, true);
    8688
    87         BakedTreeEvaluator evaluator = new BakedTreeEvaluator();
     89        ITreeEvaluator evaluator = GetVariableValue<ITreeEvaluator>(TREEEVALUATOR, bestScope, true);
    8890        evaluator.PrepareForEvaluation(dataset, targetVariable, trainingSamplesStart, trainingSamplesEnd, 1.0, gpModel.FunctionTree);
    8991        for(int i = 0; i < (samplesEnd - samplesStart); i++) {
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Addition.cs

    r2202 r2211  
    4242      : base() {
    4343      // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    44       MinArity = 2;
    45       MaxArity = 3;
     44      MinSubTrees = 2;
     45      MaxSubTrees = 3;
    4646    }
    4747  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/And.cs

    r2202 r2211  
    3838    public And()
    3939      : base() {
    40       MinArity = 2; MaxArity = 3;
     40      MinSubTrees = 2; MaxSubTrees = 3;
    4141    }
    4242  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Average.cs

    r2202 r2211  
    3636    public Average()
    3737      : base() {
    38       MinArity = 2; MaxArity = 3;
     38      MinSubTrees = 2; MaxSubTrees = 3;
    3939    }
    4040  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/ConstantFunctionTree.cs

    r2210 r2211  
    2929namespace HeuristicLab.GP.StructureIdentification {
    3030  public class ConstantFunctionTree : FunctionTreeBase {
     31    private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
    3132    public double Value { get; set; }
    3233
    33     public ConstantFunctionTree(Constant constant)
    34       : base(constant) {
     34    public ConstantFunctionTree(Constant constant) {
     35      Function = constant;
    3536    }
    3637
    37     protected ConstantFunctionTree(ConstantFunctionTree original)
    38       : base(original) {
     38    protected ConstantFunctionTree(ConstantFunctionTree original) {
     39      Function = original.Function;
    3940      Value = original.Value;
     41    }
     42
     43    public override IList<IFunctionTree> SubTrees {
     44      get {
     45        return subTrees;
     46      }
    4047    }
    4148
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/FunctionLibraryInjector.cs

    r2210 r2211  
    238238
    239239    private void SetAllowedSubOperators(IFunction f, List<IFunction> gs) {
    240       for (int i = 0; i < f.MaxArity; i++) {
     240      for (int i = 0; i < f.MaxSubTrees; i++) {
    241241        SetAllowedSubOperators(f, i, gs);
    242242      }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HL3TreeEvaluator.cs

    r2202 r2211  
    3434  /// Not thread-safe!
    3535  /// </summary>
    36   public class BakedTreeEvaluator : TreeEvaluatorBase {
     36  public class HL3TreeEvaluator : TreeEvaluatorBase {
    3737
    3838
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/HeuristicLab.GP.StructureIdentification-3.3.csproj

    r2210 r2211  
    8585    <Compile Include="And.cs" />
    8686    <Compile Include="Average.cs" />
    87     <Compile Include="BakedTreeEvaluator.cs" />
    8887    <Compile Include="Constant.cs" />
    8988    <Compile Include="AlgorithmBase.cs" />
    9089    <Compile Include="ConstantFunctionTree.cs" />
    9190    <Compile Include="Evaluators\SimpleGPEvaluatorBase.cs" />
     91    <Compile Include="HL3TreeEvaluator.cs" />
    9292    <Compile Include="VariableFunctionTree.cs" />
    9393    <Compile Include="TreeEvaluatorBase.cs" />
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/IfThenElse.cs

    r2202 r2211  
    3838    public IfThenElse()
    3939      : base() {
    40       MinArity = 3; MaxArity = 3;
     40      MinSubTrees = 3; MaxSubTrees = 3;
    4141    }
    4242  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Multiplication.cs

    r2202 r2211  
    4343      : base() {
    4444      // 2 - 3 seems like an reasonable defaut (used for +,-,*,/) (discussion with swinkler and maffenze)
    45       MinArity = 2; MaxArity = 3;
     45      MinSubTrees = 2; MaxSubTrees = 3;
    4646    }
    4747  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/Or.cs

    r2202 r2211  
    3737    public Or()
    3838      : base() {
    39       MinArity = 2; MaxArity = 3;
     39      MinSubTrees = 2; MaxSubTrees = 3;
    4040    }
    4141  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP.StructureIdentification/3.3/VariableFunctionTree.cs

    r2210 r2211  
    2929namespace HeuristicLab.GP.StructureIdentification {
    3030  public class VariableFunctionTree : FunctionTreeBase {
     31    private static readonly IList<IFunctionTree> subTrees = new List<IFunctionTree>().AsReadOnly();
    3132    public double Weight { get; set; }
    3233    public string VariableName { get; set; }
    3334    public int SampleOffset { get; set; }
    3435
    35     public VariableFunctionTree(Variable variable)
    36       : base(variable) {
     36    public VariableFunctionTree(Variable variable) {
     37      Function = variable;
    3738    }
    3839
    39     protected VariableFunctionTree(VariableFunctionTree original)
    40       : base(original) {
     40    protected VariableFunctionTree(VariableFunctionTree original) {
     41      Function = original.Function;
    4142      Weight = original.Weight;
    4243      VariableName = original.VariableName;
    4344      SampleOffset = original.SampleOffset;
     45    }
     46
     47    public override IList<IFunctionTree> SubTrees {
     48      get {
     49        return subTrees;
     50      }
    4451    }
    4552
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/BinaryFunction.cs

    r2210 r2211  
    3030    public BinaryFunction()
    3131      : base() {
    32       MinArity = 2; MaxArity = 2;
     32      MinSubTrees = 2; MaxSubTrees = 2;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionBase.cs

    r2210 r2211  
    4949    }
    5050
    51     public int MinArity {
     51    public int MinSubTrees {
    5252      get {
    5353        return minArity;
     
    5959    }
    6060
    61     public int MaxArity {
     61    public int MaxSubTrees {
    6262      get {
    6363        return maxArity;
     
    128128
    129129    public ICollection<IFunction> GetAllowedSubFunctions(int index) {
    130       if (index < 0 || index > MaxArity) 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);
    131131      //if (allowedSubFunctions == null) {
    132132      //  // first time: analyze the constraint and create a cached copy of the allowed sub-functions
     
    140140
    141141    public void AddAllowedSubFunction(IFunction function, int index) {
    142       if (index < 0 || index > MaxArity) 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);
    143143      if (allowedSubFunctions[index] == null) {
    144144        allowedSubFunctions[index] = new List<IFunction>();
     
    150150
    151151    public void RemoveAllowedSubFunction(IFunction function, int index) {
    152       if (index < 0 || index > MaxArity) 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);
    153153      allowedSubFunctions[index].Add(function);
    154154    }
     
    190190      int sum = 1;
    191191      int minSize = int.MaxValue;
    192       for (int i = 0; i < MinArity; i++) {
     192      for (int i = 0; i < MinSubTrees; i++) {
    193193        foreach (IFunction subFun in GetAllowedSubFunctions(i)) {
    194194          minSize = Math.Min(minSize, subFun.MinTreeSize);
     
    203203      int height = 0;
    204204      int minHeight = int.MaxValue;
    205       for (int i = 0; i < MinArity; i++) {
     205      for (int i = 0; i < MinSubTrees; i++) {
    206206        foreach (IFunction subFun in GetAllowedSubFunctions(i)) {
    207207          minHeight = Math.Min(minHeight, subFun.MinTreeHeight);
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/FunctionTreeBase.cs

    r2210 r2211  
    3131    private IFunction function;
    3232
     33    public FunctionTreeBase() {
     34    }
     35
    3336    public FunctionTreeBase(IFunction function) {
    3437      subTrees = new List<IFunctionTree>();
     
    4952    }
    5053
    51     public IList<IFunctionTree> SubTrees {
     54    public virtual IList<IFunctionTree> SubTrees {
    5255      get { return subTrees; }
    5356    }
     
    5558    public IFunction Function {
    5659      get { return function; }
     60      protected set {
     61        function = value;
     62      }
    5763    }
    5864
    5965    public int GetSize() {
    6066      int size = 1;
    61       foreach (IFunctionTree tree in subTrees) size += tree.GetSize();
     67      foreach (IFunctionTree tree in SubTrees) size += tree.GetSize();
    6268      return size;
    6369    }
     
    6571    public int GetHeight() {
    6672      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());
    6874      return maxHeight + 1;
    6975    }
     
    7884
    7985    public void AddSubTree(IFunctionTree tree) {
    80       subTrees.Add(tree);
     86      SubTrees.Add(tree);
    8187    }
    8288
    83     public void InsertSubTree(int index, IFunctionTree tree) {
    84       subTrees.Insert(index, tree);
     89    public virtual void InsertSubTree(int index, IFunctionTree tree) {
     90      SubTrees.Insert(index, tree);
    8591    }
    8692
    87     public void RemoveSubTree(int index) {
    88       subTrees.RemoveAt(index);
     93    public virtual void RemoveSubTree(int index) {
     94      SubTrees.RemoveAt(index);
    8995    }
    9096
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/Terminal.cs

    r2210 r2211  
    3030    public Terminal()
    3131      : base() {
    32       MinArity = 0; MaxArity = 0;
     32      MinSubTrees = 0; MaxSubTrees = 0;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/BaseClasses/UnaryFunction.cs

    r2210 r2211  
    3030    public UnaryFunction()
    3131      : base() {
    32       MinArity = 1; MaxArity = 1;
     32      MinSubTrees = 1; MaxSubTrees = 1;
    3333    }
    3434  }
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/ChangeNodeTypeManipulation.cs

    r2210 r2211  
    136136      IFunction selectedFunction = allowedFunctions[random.Next(allowedFunctions.Count)];
    137137      // arity of the selected operator
    138       int minArity = selectedFunction.MinArity;
    139       int maxArity = selectedFunction.MaxArity;
     138      int minArity = selectedFunction.MinSubTrees;
     139      int maxArity = selectedFunction.MaxSubTrees;
    140140      // if the old child had too many sub-trees then the new child should keep as many sub-trees as possible
    141141      if (actualArity > maxArity)
  • branches/GP-Refactoring-713/sources/HeuristicLab.GP/3.3/Manipulation/DeleteSubTreeManipulation.cs

    r2210 r2211  
    5959      // select a branch to prune
    6060      int childIndex = random.Next(parent.SubTrees.Count);
    61       if (parent.SubTrees.Count > parent.Function.MinArity) {
     61      if (parent.SubTrees.Count > parent.Function.MinSubTrees) {
    6262        parent.RemoveSubTree(childIndex);
    6363        // 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  
    5959      // init functions and terminals based on constraints
    6060      foreach(IFunction fun in funLibrary.Functions) {
    61         if(fun.MaxArity == 0) {
     61        if(fun.MaxSubTrees == 0) {
    6262          terminals.Add(fun);
    6363          allFunctions.Add(fun);
     
    107107      int currentSize = 1;
    108108      int totalListMinSize = 0;
    109       int minArity = root.Function.MinArity;
    110       int maxArity = root.Function.MaxArity;
     109      int minArity = root.Function.MinSubTrees;
     110      int maxArity = root.Function.MaxSubTrees;
    111111      if (maxArity >= size) {
    112112        maxArity = size;
     
    142142          totalListMinSize--;
    143143
    144           minArity = selectedFunction.MinArity;
    145           maxArity = selectedFunction.MaxArity;
     144          minArity = selectedFunction.MinSubTrees;
     145          maxArity = selectedFunction.MaxSubTrees;
    146146          if (maxArity >= size) {
    147147            maxArity = size;
     
    277277      }
    278278
    279       if(tree.SubTrees.Count < tree.Function.MinArity || tree.SubTrees.Count > tree.Function.MaxArity)
     279      if(tree.SubTrees.Count < tree.Function.MinSubTrees || tree.SubTrees.Count > tree.Function.MaxSubTrees)
    280280        return false;
    281281      foreach(IFunctionTree subTree in tree.SubTrees) {
     
    306306
    307307    private bool IsPossibleParent(IFunction f, List<IFunction> children) {
    308       int minArity = f.MinArity;
    309       int maxArity = f.MaxArity;
     308      int minArity = f.MinSubTrees;
     309      int maxArity = f.MaxSubTrees;
    310310      // note: we can't assume that the operators in the children list have different types!
    311311
     
    370370    }
    371371    internal static bool IsTerminal(IFunction f) {
    372       return f.MinArity == 0 && f.MaxArity == 0;
     372      return f.MinSubTrees == 0 && f.MaxSubTrees == 0;
    373373    }
    374374    internal ICollection<IFunction> GetAllowedSubFunctions(IFunction f, int index) {
     
    397397    private IFunctionTree MakeUnbalancedTree(IFunction parent, int maxTreeHeight) {
    398398      if(maxTreeHeight == 0) return parent.GetTreeNode();
    399       int minArity = parent.MinArity;
    400       int maxArity = parent.MaxArity;
     399      int minArity = parent.MinSubTrees;
     400      int maxArity = parent.MaxSubTrees;
    401401      int actualArity = random.Next(minArity, maxArity + 1);
    402402      if(actualArity > 0) {
     
    418418    private IFunctionTree MakeBalancedTree(IFunction parent, int maxTreeHeight) {
    419419      if(maxTreeHeight == 0) return parent.GetTreeNode();
    420       int minArity = parent.MinArity;
    421       int maxArity = parent.MaxArity;
     420      int minArity = parent.MinSubTrees;
     421      int maxArity = parent.MaxSubTrees;
    422422      int actualArity = random.Next(minArity, maxArity + 1);
    423423      if(actualArity > 0) {
Note: See TracChangeset for help on using the changeset viewer.