Changeset 17463 for branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
- Timestamp:
- 03/02/20 15:04:46 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
r17460 r17463 105 105 int row = rowEnum; 106 106 var result = Evaluate(dataset, ref row, state); 107 if (!result.IsScalar) 108 throw new InvalidOperationException("Result of the tree is not a scalar."); 109 yield return result.Scalar; 107 if (result.IsScalar) 108 yield return result.Scalar; 109 else 110 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; 110 114 state.Reset(); 111 115 } … … 148 152 149 153 public DoubleVector Vector { get; } 150 public bool IsVector => !(Vector.Count == 1 && double.IsNaN(Vector[0])); 154 public bool IsVector => Vector != null; 155 //public bool IsVector => !(Vector.Count == 1 && double.IsNaN(Vector[0])); 151 156 152 157 public bool IsNaN => !IsScalar && !IsVector; … … 154 159 public EvaluationResult(double scalar) { 155 160 Scalar = scalar; 156 Vector = NaNVector; 161 //Vector = NaNVector; 162 Vector = null; 157 163 } 158 164 public EvaluationResult(DoubleVector vector) { 165 if (vector == null) throw new ArgumentNullException(nameof(vector)); 159 166 Vector = vector; 160 167 Scalar = double.NaN; … … 168 175 169 176 public static readonly EvaluationResult NaN = new EvaluationResult(double.NaN); 170 private static readonly DoubleVector NaNVector = DoubleVector.Build.Dense(1, double.NaN);177 //private static readonly DoubleVector NaNVector = DoubleVector.Build.Dense(1, double.NaN); 171 178 } 172 179 … … 180 187 if (lhs.IsVector && rhs.IsScalar && vsFunc != null) return new EvaluationResult(vsFunc(lhs.Vector, rhs.Scalar)); 181 188 if (lhs.IsVector && rhs.IsVector && vvFunc != null) return new EvaluationResult(vvFunc(lhs.Vector, rhs.Vector)); 182 throw new NotSupportedException($"Unsupported combination of argument types: ({lhs}) / ({rhs})"); 189 return EvaluationResult.NaN; 190 //throw new NotSupportedException($"Unsupported combination of argument types: ({lhs}) / ({rhs})"); 183 191 } 184 192 … … 188 196 if (val.IsScalar && sFunc != null) return new EvaluationResult(sFunc(val.Scalar)); 189 197 if (val.IsVector && vFunc != null) return new EvaluationResult(vFunc(val.Vector)); 190 throw new NotSupportedException($"Unsupported argument type ({val})"); 198 return EvaluationResult.NaN; 199 //throw new NotSupportedException($"Unsupported argument type ({val})"); 191 200 } 192 201 private static EvaluationResult AggregateApply(EvaluationResult val, … … 195 204 if (val.IsScalar && sFunc != null) return new EvaluationResult(sFunc(val.Scalar)); 196 205 if (val.IsVector && vFunc != null) return new EvaluationResult(vFunc(val.Vector)); 197 throw new NotSupportedException($"Unsupported argument type ({val})"); 206 return EvaluationResult.NaN; 207 //throw new NotSupportedException($"Unsupported argument type ({val})"); 198 208 } 199 209 … … 335 345 v => v.Mean()); 336 346 } 347 case OpCodes.StandardDeviation: { 348 var cur = Evaluate(dataset, ref row, state); 349 return AggregateApply(cur, 350 s => 0, 351 v => v.Count > 1 ? Statistics.StandardDeviation(v) : 0); 352 } 337 353 case OpCodes.Variable: { 338 354 if (row < 0 || row >= dataset.Rows) return EvaluationResult.NaN;
Note: See TracChangeset
for help on using the changeset viewer.