Changeset 17467 for branches/3040_VectorBasedGP
- Timestamp:
- 03/03/20 12:00:52 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
r17466 r17467 22 22 using System; 23 23 using System.Collections.Generic; 24 using HeuristicLab.Analysis;25 24 using HeuristicLab.Common; 26 25 using HeuristicLab.Core; … … 29 28 using HeuristicLab.Parameters; 30 29 using HEAL.Attic; 31 using MathNet.Numerics.LinearAlgebra;32 30 using MathNet.Numerics.Statistics; 33 31 … … 38 36 [Item("SymbolicDataAnalysisExpressionTreeVectorInterpreter", "Interpreter for symbolic expression trees including vector arithmetic.")] 39 37 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 } 40 46 41 47 private const string EvaluatedSolutionsParameterName = "EvaluatedSolutions"; 48 private const string FinalAggregationParameterName = "FinalAggregation"; 42 49 43 50 public override bool CanChangeName { … … 52 59 public IFixedValueParameter<IntValue> EvaluatedSolutionsParameter { 53 60 get { return (IFixedValueParameter<IntValue>)Parameters[EvaluatedSolutionsParameterName]; } 61 } 62 public IFixedValueParameter<EnumValue<Aggregation>> FinalAggregationParameter { 63 get { return (IFixedValueParameter<EnumValue<Aggregation>>)Parameters[FinalAggregationParameterName]; } 54 64 } 55 65 #endregion … … 60 70 set { EvaluatedSolutionsParameter.Value.Value = value; } 61 71 } 72 public Aggregation FinalAggregation { 73 get { return FinalAggregationParameter.Value.Value; } 74 set { FinalAggregationParameter.Value.Value = value; } 75 } 62 76 #endregion 63 77 … … 73 87 74 88 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.") { 77 90 } 78 91 … … 80 93 : base(name, description) { 81 94 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))); 82 96 } 83 97 84 98 [StorableHook(HookType.AfterDeserialization)] 85 99 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 } 87 103 } 88 104 … … 107 123 if (result.IsScalar) 108 124 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 110 132 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;114 133 state.Reset(); 115 134 }
Note: See TracChangeset
for help on using the changeset viewer.