Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/22/19 16:31:11 (5 years ago)
Author:
pfleck
Message:

#3040

  • Added VectorVariable and its corresponding TreeNode.
  • Added symbols for basic vector operations and symbols for sum and avg of vectors.
  • Added a VectorEvaluate method in the SymbolicDataAnalysisExpressionTreeInterpreter that returns a DoubleVector instead of a double that is also called within the regular Evaluate method.
Location:
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/DoubleVector.cs

    r17365 r17367  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
     24using System.Linq;
     25using System.Windows.Markup;
    2326using HEAL.Attic;
    2427
     
    3538      : base(_) { }
    3639
     40    public static DoubleVector operator +(DoubleVector lhs, DoubleVector rhs) {
     41      return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l + r));
     42    }
     43    public static DoubleVector operator -(DoubleVector lhs, DoubleVector rhs) {
     44      return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l - r));
     45    }
     46    public static DoubleVector operator *(DoubleVector lhs, DoubleVector rhs) {
     47      return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l * r));
     48    }
     49    public static DoubleVector operator /(DoubleVector lhs, DoubleVector rhs) {
     50      return new DoubleVector(VecCalc(lhs, rhs, (l, r) => l / r));
     51    }
     52    private static IEnumerable<double> VecCalc(IReadOnlyList<double> lhs, IReadOnlyList<double> rhs, Func<double, double, double> resultFunc) {
     53      if (lhs.Count != rhs.Count) throw new InvalidOperationException("Vectors are not of equal length.");
     54      return lhs.Zip(rhs, resultFunc);
     55    }
     56
     57    public static DoubleVector operator +(DoubleVector lhs, double rhs) {
     58      return new DoubleVector(lhs.Select(l => l + rhs));
     59    }
     60    public static DoubleVector operator -(DoubleVector lhs, double rhs) {
     61      return new DoubleVector(lhs.Select(l => l - rhs));
     62    }
     63    public static DoubleVector operator *(DoubleVector lhs, double rhs) {
     64      return new DoubleVector(lhs.Select(l => l * rhs));
     65    }
     66    public static DoubleVector operator /(DoubleVector lhs, double rhs) {
     67      return new DoubleVector(lhs.Select(l => l / rhs));
     68    }
     69
     70    public double Sum() {
     71      return values.Sum();
     72    }
     73
     74    public double Average() {
     75      return values.Average();
     76    }
    3777  }
    3878}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Vectors/Vector.cs

    r17365 r17367  
    2828  [StorableType("3574E222-1167-4F1B-93D2-01B15A7F1E84")]
    2929  public abstract class Vector<T> : IVector<T> {
    30     private readonly List<T> values;
     30    [Storable]
     31    protected readonly List<T> values;
    3132
    3233    protected Vector(IEnumerable<T> values) {
Note: See TracChangeset for help on using the changeset viewer.