Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17467


Ignore:
Timestamp:
03/03/20 12:00:52 (5 years ago)
Author:
pfleck
Message:

#3040 Added a "final aggregation" option for the vector interpreter in case the result is a vector.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs

    r17466 r17467  
    2222using System;
    2323using System.Collections.Generic;
    24 using HeuristicLab.Analysis;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
     
    2928using HeuristicLab.Parameters;
    3029using HEAL.Attic;
    31 using MathNet.Numerics.LinearAlgebra;
    3230using MathNet.Numerics.Statistics;
    3331
     
    3836  [Item("SymbolicDataAnalysisExpressionTreeVectorInterpreter", "Interpreter for symbolic expression trees including vector arithmetic.")]
    3937  public class SymbolicDataAnalysisExpressionTreeVectorInterpreter : ParameterizedNamedItem, ISymbolicDataAnalysisExpressionTreeInterpreter {
     38    [StorableType("2612504E-AD5F-4AE2-B60E-98A5AB59E164")]
     39    public enum Aggregation {
     40      Mean,
     41      Median,
     42      Sum,
     43      NaN,
     44      Exception
     45    }
    4046
    4147    private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions";
     48    private const string FinalAggregationParameterName = "FinalAggregation";
    4249
    4350    public override bool CanChangeName {
     
    5259    public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter {
    5360      get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; }
     61    }
     62    public IFixedValueParameter<EnumValue<Aggregation>> FinalAggregationParameter {
     63      get { return (IFixedValueParameter<EnumValue<Aggregation>>)Parameters[FinalAggregationParameterName]; }
    5464    }
    5565    #endregion
     
    6070      set { EvaluatedSolutionsParameter.Value.Value = value; }
    6171    }
     72    public Aggregation FinalAggregation {
     73      get { return FinalAggregationParameter.Value.Value; }
     74      set { FinalAggregationParameter.Value.Value = value; }
     75    }
    6276    #endregion
    6377
     
    7387
    7488    public SymbolicDataAnalysisExpressionTreeVectorInterpreter()
    75       : base("SymbolicDataAnalysisExpressionTreeVectorInterpreter", "Interpreter for symbolic expression trees including vector arithmetic.") {
    76       Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     89      : this("SymbolicDataAnalysisExpressionTreeVectorInterpreter", "Interpreter for symbolic expression trees including vector arithmetic.") {
    7790    }
    7891
     
    8093      : base(name, description) {
    8194      Parameters.Add(new FixedValueParameter<IntValue>(EvaluatedSolutionsParameterName, "A counter for the total number of solutions the interpreter has evaluated", new IntValue(0)));
     95      Parameters.Add(new FixedValueParameter<EnumValue<Aggregation>>(FinalAggregationParameterName, "If root node of the expression tree results in a Vector it is aggregated according to this parameter", new EnumValue<Aggregation>(Aggregation.Mean)));
    8296    }
    8397
    8498    [StorableHook(HookType.AfterDeserialization)]
    8599    private void AfterDeserialization() {
    86 
     100      if (!Parameters.ContainsKey(FinalAggregationParameterName)) {
     101        Parameters.Add(new FixedValueParameter<EnumValue<Aggregation>>(FinalAggregationParameterName, "If root node of the expression tree results in a Vector it is aggregated according to this parameter", new EnumValue<Aggregation>(Aggregation.Mean)));
     102      }
    87103    }
    88104
     
    107123        if (result.IsScalar)
    108124          yield return result.Scalar;
    109         else
     125        else if (result.IsVector) {
     126          if (FinalAggregation == Aggregation.Mean) yield return result.Vector.Mean();
     127          else if (FinalAggregation == Aggregation.Median) yield return Statistics.Median(result.Vector);
     128          else if (FinalAggregation == Aggregation.Sum) yield return result.Vector.Sum();
     129          else if (FinalAggregation == Aggregation.Exception) throw new InvalidOperationException("Result of the tree is not a scalar.");
     130          else yield return double.NaN;
     131        } else
    110132          yield return double.NaN;
    111         //if (!result.IsScalar)
    112         //  throw new InvalidOperationException("Result of the tree is not a scalar.");
    113         //yield return result.Scalar;
    114133        state.Reset();
    115134      }
Note: See TracChangeset for help on using the changeset viewer.