Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17604


Ignore:
Timestamp:
06/17/20 11:23:37 (4 years ago)
Author:
pfleck
Message:

#3040 Stores the datatype of a tree node (e.g. variable nodes) in the tree itself for the interpreter to derive the datatypes for subtrees. This way, the interpreter (and simplifier) do not need an actual dataset to figure out datatypes for subtrees.

Location:
branches/3040_VectorBasedGP
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs

    r17180 r17604  
    3333    bool HasLocalParameters { get; }
    3434
     35    // Can be null for "unknown"
     36    Type DataType { get; }
     37
    3538    int GetDepth();
    3639    int GetLength();
  • branches/3040_VectorBasedGP/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs

    r17180 r17604  
    9696    }
    9797
     98    public virtual Type DataType {
     99      get { return null; }
     100    }
     101
    98102    public virtual IEnumerable<ISymbolicExpressionTreeNode> Subtrees {
    99103      get { return subtrees; }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r17593 r17604  
    315315    private void btnSimplify_Click(object sender, EventArgs e) {
    316316      if (Content.Model.Interpreter is SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter) { // TODO: Own interface for data-dependent node-types-interpreter?
    317         var simplifier = new VectorTreeSimplifier(interpreter, Content.ProblemData);
     317        var simplifier = new VectorTreeSimplifier(interpreter);
    318318        var simplifiedExpressionTree = simplifier.Simplify(Content.Model.SymbolicExpressionTree);
    319319        UpdateModel(simplifiedExpressionTree);
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Converters/VectorTreeSimplifier.cs

    r17603 r17604  
    2727using HeuristicLab.Common;
    2828using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29
     30using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
    2931
    3032namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
     
    6668
    6769    private readonly SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter;
    68     private readonly IDataAnalysisProblemData problemData;
    69 
    70     public VectorTreeSimplifier(SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter, IDataAnalysisProblemData problemData) {
     70
     71    public VectorTreeSimplifier(SymbolicDataAnalysisExpressionTreeVectorInterpreter interpreter) {
    7172      this.interpreter = interpreter;
    72       this.problemData = problemData;
    7373    }
    7474
     
    286286    #region type predicates
    287287    public bool IsScalarNode(ISymbolicExpressionTreeNode node) {
    288       var results = interpreter.EvaluateNode(node, problemData.Dataset, problemData.TrainingIndices);
    289       return results.All(r => r.IsScalar);
     288      return interpreter.GetNodeType(node) == typeof(double);
    290289    }
    291290    public bool IsVectorNode(ISymbolicExpressionTreeNode node) {
    292       var results = interpreter.EvaluateNode(node, problemData.Dataset, problemData.TrainingIndices);
    293       return results.All(r => r.IsVector);
     291      return interpreter.GetNodeType(node) == typeof(DoubleVector);
    294292    }
    295293    #endregion
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/TypeCoherentVectorExpressionGrammar.cs

    r17554 r17604  
    130130      var powerSymbols = new GroupSymbol(PowerFunctionsName, new List<ISymbol> { square, sqrt, cube, cubeRoot, power, root });
    131131      var terminalSymbols = new GroupSymbol(TerminalsName, new List<ISymbol> { constant, variable, binFactorVariable, factorVariable });
    132       var statisticsSymbols = new GroupSymbol(VectorStatisticsName, new List<ISymbol> {mean, sd, sum, length, min, max, variance, skewness, kurtosis});
     132      var statisticsSymbols = new GroupSymbol(VectorStatisticsName, new List<ISymbol> { mean, sd, sum, length, min, max, variance, skewness, kurtosis });
    133133      var distancesSymbols = new GroupSymbol(VectorDistancesName, new List<ISymbol> { euclideanDistance, covariance });
    134134      var aggregationSymbols = new GroupSymbol(VectorAggregationName, new List<ISymbol> { statisticsSymbols, distancesSymbols });
     
    217217          varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<double>(x));
    218218          varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<double>(x));
     219          varSymbol.VariableDataType = typeof(double);
    219220        }
    220221      }
     
    223224          varSymbol.AllVariableNames = problemData.InputVariables.Select(x => x.Value).Where(x => dataset.VariableHasType<DoubleVector>(x));
    224225          varSymbol.VariableNames = problemData.AllowedInputVariables.Where(x => dataset.VariableHasType<DoubleVector>(x));
     226          varSymbol.VariableDataType = typeof(DoubleVector);
    225227        }
    226228      }
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs

    r17602 r17604  
    4646      Exception
    4747    }
     48
     49    #region Aggregation Symbols
     50    private static Type[] AggregationSymbols = new[] {
     51      typeof(Sum), typeof(Mean), typeof(Length), typeof(StandardDeviation), typeof(Variance),
     52      typeof(EuclideanDistance), typeof(Covariance)
     53    };
     54    #endregion
    4855
    4956    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
     
    254261    }
    255262
    256     public virtual IEnumerable<EvaluationResult> EvaluateNode(ISymbolicExpressionTreeNode node, IDataset dataset, IEnumerable<int> rows) {
    257       //lock (syncRoot) {
    258       //  EvaluatedSolutions++; // increment the evaluated solutions counter
    259       //}
    260 
    261       var startNode = new StartSymbol().CreateTreeNode();
    262       startNode.AddSubtree(node);
    263       var programNode = new ProgramRootSymbol().CreateTreeNode();
    264       programNode.AddSubtree(startNode);
    265       var tree = new SymbolicExpressionTree(programNode);
    266 
    267       var state = PrepareInterpreterState(tree, dataset);
    268 
    269       foreach (var rowEnum in rows) {
    270         int row = rowEnum;
    271         var result = Evaluate(dataset, ref row, state);
    272         yield return result;
    273         state.Reset();
    274       }
     263    public virtual Type GetNodeType(ISymbolicExpressionTreeNode node) {
     264      if (node.DataType != null)
     265        return node.DataType;
     266
     267      if (AggregationSymbols.Contains(node.Symbol.GetType()))
     268        return typeof(double);
     269
     270      var argumentTypes = node.Subtrees.Select(GetNodeType);
     271      if (argumentTypes.Any(t => t == typeof(DoubleVector)))
     272        return typeof(DoubleVector);
     273
     274      return typeof(double);
    275275    }
    276276
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/ConstantTreeNode.cs

    r17180 r17604  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3738      get { return constantValue; }
    3839      set { constantValue = value; }
     40    }
     41
     42    public override Type DataType {
     43      get { return typeof(double); }
    3944    }
    4045
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/FactorVariableTreeNode.cs

    r17180 r17604  
    4444      get { return variableName; }
    4545      set { variableName = value; }
     46    }
     47
     48    public override Type DataType {
     49      get { return typeof(double); }
    4650    }
    4751
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableBase.cs

    r17180 r17604  
    142142      get { return maximumArity; }
    143143    }
     144
     145    [Storable]
     146    private Type variableDataType;
     147    public Type VariableDataType {
     148      get { return variableDataType; }
     149      set {
     150        if (variableDataType == value) return;
     151        variableDataType = value;
     152        OnChanged(EventArgs.Empty);
     153      }
     154    }
    144155    #endregion
    145156
     
    166177      multiplicativeWeightManipulatorSigma = original.multiplicativeWeightManipulatorSigma;
    167178      variableChangeProbability = original.variableChangeProbability;
     179      variableDataType = original.variableDataType;
    168180    }
    169181    protected VariableBase(string name, string description)
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/VariableTreeNodeBase.cs

    r17180 r17604  
    2020#endregion
    2121
     22using System;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    4243      get { return variableName; }
    4344      set { variableName = value; }
     45    }
     46
     47    public override Type DataType {
     48      get { return Symbol.VariableDataType; }
    4449    }
    4550
Note: See TracChangeset for help on using the changeset viewer.