Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3257


Ignore:
Timestamp:
04/02/10 16:49:20 (14 years ago)
Author:
gkronber
Message:

Moved general set of symbols and evaluator into Encodings.SymbolicExpressionTreeEncoding. #937 (Data types and operators for symbolic expression tree encoding)

Location:
trunk/sources
Files:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs

    r3251 r3257  
    2727using HeuristicLab.Core;
    2828using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
    2930namespace HeuristicLab.Problems.ArtificialAnt {
    3031  [StorableClass]
    3132  public class ArtificialAntExpressionGrammar : Item, ISymbolicExpressionGrammar {
    32 
    33     private class EmptySymbol : Symbol { }
    3433
    3534    public ArtificialAntExpressionGrammar()
     
    3938
    4039    [Storable]
    41     private EmptySymbol startSymbol = new EmptySymbol();
     40    private StartSymbol startSymbol = new StartSymbol();
    4241    public Symbol StartSymbol {
    4342      get { return startSymbol; }
     
    5655    private Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols = new Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>>() {
    5756      {
    58         typeof(EmptySymbol),
     57        typeof(StartSymbol),
    5958        new Dictionary<int, IEnumerable<Symbol>>()
    6059        {
     
    9392    [Storable]
    9493    private Dictionary<Type, int> minLength = new Dictionary<Type, int>() {
    95       {typeof(EmptySymbol), 1},
     94      {typeof(StartSymbol), 1},
    9695      {typeof(IfFoodAhead), 3},
    9796      {typeof(Prog2), 3},
     
    107106    [Storable]
    108107    private Dictionary<Type, int> maxLength = new Dictionary<Type, int>() {
    109       {typeof(EmptySymbol), int.MaxValue},
     108      {typeof(StartSymbol), int.MaxValue},
    110109      {typeof(IfFoodAhead), int.MaxValue},
    111110      {typeof(Prog2), int.MaxValue},
     
    121120    [Storable]
    122121    private Dictionary<Type, int> minDepth = new Dictionary<Type, int>() {
    123       {typeof(EmptySymbol), 1},
     122      {typeof(StartSymbol), 1},
    124123      {typeof(IfFoodAhead), 1},
    125124      {typeof(Prog2), 1},
     
    136135    [Storable]
    137136    private Dictionary<Type, int> subTrees = new Dictionary<Type, int>() {
    138       {typeof(EmptySymbol), 1},
     137      {typeof(StartSymbol), 1},
    139138      {typeof(IfFoodAhead), 2},
    140139      {typeof(Prog2), 2},
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/HeuristicLab.Problems.DataAnalysis.Regression-3.3.csproj

    r3253 r3257  
    8585    <None Include="HeuristicLabProblemsDataAnalysisRegressionPlugin.cs.frame" />
    8686    <None Include="Properties\AssemblyInfo.frame" />
     87    <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" />
     88    <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" />
    8789    <Compile Include="Symbolic\SymbolicRegressionMeanSquaredErrorEvaluator.cs" />
    8890    <Compile Include="Symbolic\SymbolicRegressionEvaluator.cs" />
     
    98100      <DependentUpon>SymbolicRegressionProblemView.cs</DependentUpon>
    99101    </Compile>
     102    <Compile Include="Symbolic\Symbols\Constant.cs" />
     103    <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
     104    <Compile Include="Symbolic\Symbols\Variable.cs" />
     105    <Compile Include="Symbolic\Symbols\VariableTreeNode.cs" />
    100106  </ItemGroup>
    101107  <ItemGroup>
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/ArithmeticExpressionGrammar.cs

    r3255 r3257  
    2626using System.Linq;
    2727using HeuristicLab.Core;
    28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
    2928using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     30using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols;
     31namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    3132  [StorableClass]
    3233  public class ArithmeticExpressionGrammar : Item, ISymbolicExpressionGrammar {
    33 
    34     private class EmptySymbol : Symbol {
    35       public EmptySymbol() {
    36         Name = "Start";
    37       }
    38     }
    3934
    4035    public ArithmeticExpressionGrammar()
     
    4338    #region ISymbolicExpressionGrammar Members
    4439    [Storable]
    45     private EmptySymbol startSymbol = new EmptySymbol();
     40    private StartSymbol startSymbol = new StartSymbol();
    4641    public Symbol StartSymbol {
    4742      get { return startSymbol; }
     
    5550      new Division(),
    5651      new Constant(),
    57       new HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable()
     52      new HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable()
    5853    };
    5954    [Storable]
    6055    private Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols = new Dictionary<Type, Dictionary<int, IEnumerable<Symbol>>>() {
    6156      {
    62         typeof(EmptySymbol),
     57        typeof(StartSymbol),
    6358        new Dictionary<int, IEnumerable<Symbol>>()
    6459        {
     
    10499    [Storable]
    105100    private Dictionary<Type, int> minLength = new Dictionary<Type, int>() {
    106       {typeof(EmptySymbol), 1},
     101      {typeof(StartSymbol), 1},
    107102      {typeof(Addition), 3},
    108103      {typeof(Subtraction), 3},
     
    110105      {typeof(Division), 4},
    111106      {typeof(Constant), 1},
    112       {typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable), 1},
     107      {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1},
    113108    };
    114109    public int MinimalExpressionLength(Symbol start) {
     
    118113    [Storable]
    119114    private Dictionary<Type, int> maxLength = new Dictionary<Type, int>() {
    120       {typeof(EmptySymbol), int.MaxValue},
     115      {typeof(StartSymbol), int.MaxValue},
    121116      {typeof(Addition), int.MaxValue},
    122117      {typeof(Subtraction), int.MaxValue},
    123118      {typeof(Multiplication), int.MaxValue},
    124119      {typeof(Division), int.MaxValue},
    125       {typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable), 1},
     120      {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 1},
    126121      {typeof(Constant), 1},
    127122    };
     
    132127    [Storable]
    133128    private Dictionary<Type, int> minDepth = new Dictionary<Type, int>() {
    134       {typeof(EmptySymbol), 1},
     129      {typeof(StartSymbol), 1},
    135130      {typeof(Addition), 1},
    136131      {typeof(Subtraction), 1},
     
    138133      {typeof(Division), 1},
    139134      {typeof(Constant), 0},
    140       {typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable), 0}
     135      {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0}
    141136    };
    142137    public int MinimalExpressionDepth(Symbol start) {
     
    146141    [Storable]
    147142    private Dictionary<Type, int> subTrees = new Dictionary<Type, int>() {
    148       {typeof(EmptySymbol), 1},
     143      {typeof(StartSymbol), 1},
    149144      {typeof(Addition), 2},
    150145      {typeof(Subtraction), 2},
    151146      {typeof(Multiplication), 2},
    152147      {typeof(Division), 2},
    153       {typeof(HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable), 0},
     148      {typeof(HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable), 0},
    154149      {typeof(Constant), 0},
    155150    };
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SimpleArithmeticExpressionEvaluator.cs

    r3255 r3257  
    2626using System.Collections.Generic;
    2727using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    28 using HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols;
     28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
     29using HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols;
    2930
    30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     31namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
    3132  /// <summary>
    3233  /// Evaluates FunctionTrees recursively by interpretation of the function symbols in each node.
     
    3637  [StorableClass]
    3738  [Item("SimpleArithmeticExpressionEvaluator", "Default evaluator for arithmetic symbolic expression trees.")]
    38   public class SimpleArithmeticExpressionEvaluator : Item {
     39  public class SimpleArithmeticExpressionEvaluator : GeneralSymbolicExpressionTreeEvaluator {
     40    private Dataset dataset;
     41    private int row;
    3942    public IEnumerable<double> EstimatedValues(SymbolicExpressionTree tree, Dataset dataset, IEnumerable<int> rows) {
     43      this.dataset = dataset;
    4044      foreach (var row in rows) {
    41         var estimatedValue = Evaluate(tree.Root.SubTrees[0], dataset, row);
     45        this.row = row;
     46        var estimatedValue = Evaluate(tree.Root.SubTrees[0]);
    4247        if (double.IsNaN(estimatedValue) || double.IsInfinity(estimatedValue)) yield return 0.0;
    4348        else yield return estimatedValue;
     
    4550    }
    4651
    47     private double Evaluate(SymbolicExpressionTreeNode node, Dataset dataset, int row) {
    48       if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Symbolic.Symbols.Variable) {
     52    public override double Evaluate(SymbolicExpressionTreeNode node) {
     53      if (node.Symbol is HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Symbols.Variable) {
    4954        var variableTreeNode = node as VariableTreeNode;
    5055        return dataset[row, 1 /*dataset.VariableIndex(variableTreeNode.VariableName)*/] * 1.0; //variableTreeNode.Weight;
    5156      } else if (node.Symbol is Constant) {
    5257        return ((ConstantTreeNode)node).Value;
    53       } else if (node.Symbol is Addition) {
    54         return Evaluate(node.SubTrees[0], dataset, row) + Evaluate(node.SubTrees[1], dataset, row);
    55       } else if (node.Symbol is Subtraction) {
    56         return Evaluate(node.SubTrees[0], dataset, row) - Evaluate(node.SubTrees[1], dataset, row);
    57       } else if (node.Symbol is Multiplication) {
    58         return Evaluate(node.SubTrees[0], dataset, row) * Evaluate(node.SubTrees[1], dataset, row);
    59       } else if (node.Symbol is Division) {
    60         return Evaluate(node.SubTrees[0], dataset, row) / Evaluate(node.SubTrees[1], dataset, row);
    6158      } else {
    62         throw new NotSupportedException("Tree contains unknown symbol: " + node.Symbol.Name);
     59        return base.Evaluate(node);
    6360      }
    6461    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionMeanSquaredErrorEvaluator.cs

    r3253 r3257  
    3434using HeuristicLab.Problems.DataAnalysis;
    3535using HeuristicLab.Operators;
    36 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3736using HeuristicLab.Problems.DataAnalysis.Evaluators;
    3837
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionProblem.cs

    r3253 r3257  
    3333using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
    3434using HeuristicLab.Problems.DataAnalysis.Regression;
    35 using HeuristicLab.Problems.DataAnalysis.Symbolic;
    3635
    3736namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/HeuristicLab.Problems.DataAnalysis-3.3.csproj

    r3253 r3257  
    8989    <Compile Include="MatrixExtensions.cs" />
    9090    <Compile Include="Properties\AssemblyInfo.cs" />
    91     <Compile Include="Symbolic\ArithmeticExpressionGrammar.cs" />
    92     <Compile Include="Symbolic\SimpleArithmeticExpressionEvaluator.cs" />
    93     <Compile Include="Symbolic\Symbols\Addition.cs" />
    94     <Compile Include="Symbolic\Symbols\Constant.cs" />
    95     <Compile Include="Symbolic\Symbols\ConstantTreeNode.cs" />
    96     <Compile Include="Symbolic\Symbols\Division.cs" />
    97     <Compile Include="Symbolic\Symbols\Multiplication.cs" />
    98     <Compile Include="Symbolic\Symbols\Subtraction.cs" />
    99     <Compile Include="Symbolic\Symbols\Variable.cs" />
    100     <Compile Include="Symbolic\Symbols\VariableTreeNode.cs" />
    10191  </ItemGroup>
    10292  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.