Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/25/20 07:41:01 (5 years ago)
Author:
pfleck
Message:

#3040 Replaced own Vector with MathNet.Numerics Vector.

Location:
branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4
Files:
2 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r17403 r17448  
    3030using HeuristicLab.Data;
    3131
     32using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
     33
    3234namespace HeuristicLab.Problems.DataAnalysis {
    3335  [Item("Dataset", "Represents a dataset containing data that should be analyzed.")]
     
    144146        else if (iter.Current[i] is DoubleVector dv)
    145147          transposed.Add(new List<DoubleVector>() { dv });
    146         else if (iter.Current[i] is StringVector sv)
    147           transposed.Add(new List<StringVector>() { sv });
    148         else if (iter.Current[i] is DateTimeVector dtv)
    149           transposed.Add(new List<DateTimeVector>() { dtv });
    150148        else throw new NotSupportedException(string.Format("Variable {0} has type {1}. This is not supported when converting from row-wise data.", vnames[i], iter.Current[i].GetType()));
    151149      }
     
    227225      get { return variableValues.Where(p => p.Value is IList<DoubleVector>).Select(p => p.Key); }
    228226    }
    229     public IEnumerable<string> StringVectorVariables {
    230       get { return variableValues.Where(p => p.Value is IList<StringVector>).Select(p => p.Key); }
    231     }
    232     public IEnumerable<string> DateTimeVectorVariables {
    233       get { return variableValues.Where(p => p.Value is IList<DateTimeVector>).Select(p => p.Key); }
    234     }
    235227
    236228    public IEnumerable<double> GetDoubleValues(string variableName) {
     
    245237    public IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName) {
    246238      return GetValues<DoubleVector>(variableName);
    247     }
    248     public IEnumerable<StringVector> GetStringVectorValues(string variableName) {
    249       return GetValues<StringVector>(variableName);
    250     }
    251     public IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName) {
    252       return GetValues<DateTimeVector>(variableName);
    253239    }
    254240
     
    299285      var values = GetValues<DoubleVector>(variableName);
    300286      return new ReadOnlyCollection<DoubleVector>(values);
    301     }
    302 
    303     public StringVector GetStringVectorValue(string variableName, int row) {
    304       var values = GetValues<StringVector>(variableName);
    305       return values[row];
    306     }
    307     public IEnumerable<StringVector> GetStringVectorValues(string variableName, IEnumerable<int> rows) {
    308       return GetValues<StringVector>(variableName, rows);
    309     }
    310     public ReadOnlyCollection<StringVector> GetReadOnlyStringVectorValues(string variableName) {
    311       var values = GetValues<StringVector>(variableName);
    312       return new ReadOnlyCollection<StringVector>(values);
    313     }
    314 
    315     public DateTimeVector GetDateTimeVectorValue(string variableName, int row) {
    316       var values = GetValues<DateTimeVector>(variableName);
    317       return values[row];
    318     }
    319     public IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName, IEnumerable<int> rows) {
    320       return GetValues<DateTimeVector>(variableName, rows);
    321     }
    322     public ReadOnlyCollection<DateTimeVector> GetReadOnlyDateTimeVectorValues(string variableName) {
    323       var values = GetValues<DateTimeVector>(variableName);
    324       return new ReadOnlyCollection<DateTimeVector>(values);
    325287    }
    326288
     
    356318    }
    357319    protected static bool IsAllowedType(Type type) {
    358       return type == typeof(double) || type == typeof(string) || type == typeof(DateTime)
    359              || type == typeof(DoubleVector) || type == typeof(StringVector) || type == typeof(DateTimeVector);
     320      return type == typeof(double) || type == typeof(string) || type == typeof(DateTime) || type == typeof(DoubleVector);
    360321    }
    361322
     
    403364
    404365      var doubleVectorValues = values as IList<DoubleVector>;
    405       if (doubleVectorValues != null) return doubleVectorValues.Select(x => new DoubleVector(x)).ToList();
    406 
    407       var stringVectorValues = values as IList<StringVector>;
    408       if (stringVectorValues != null) return stringVectorValues.Select(x => new StringVector(x)).ToList();
    409 
    410       var dateTimeVectorValues = values as IList<DateTimeVector>;
    411       if (dateTimeVectorValues != null) return dateTimeVectorValues.Select(x => new DateTimeVector(x)).ToList();
     366      if (doubleVectorValues != null) return doubleVectorValues.Select(x => DoubleVector.Build.DenseOfVector(x)).ToList();
    412367
    413368      throw new ArgumentException(string.Format("Unsupported variable type {0}.", GetElementType(values)));
     
    450405    string IStringConvertibleMatrix.GetValue(int rowIndex, int columnIndex) {
    451406      var value = variableValues[variableNames[columnIndex]][rowIndex];
    452       if (value is IVector vector) {
    453         const int maxCount = 10;
    454         string extension = vector.Count > maxCount ? ", ..." : "";
    455         return $"[{string.Join(", ", vector.Cast<object>().Take(Math.Min(vector.Count, maxCount)))}{extension}]";
     407      if (value is DoubleVector vector) {
     408        return $"[{vector.ToVectorString(10, 80)}]";
     409        //const int maxCount = 10;
     410        //string extension = vector.Count > maxCount ? ", ..." : "";
     411        //return $"[{string.Join(", ", vector.Cast<object>().Take(Math.Min(vector.Count, maxCount)))}{extension}]";
    456412      }
    457413
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r17365 r17448  
    103103      <Private>False</Private>
    104104    </Reference>
     105    <Reference Include="MathNet.Numerics, Version=4.9.0.0, Culture=neutral, processorArchitecture=MSIL">
     106      <SpecificVersion>False</SpecificVersion>
     107      <HintPath>..\..\bin\MathNet.Numerics.dll</HintPath>
     108      <Private>False</Private>
     109    </Reference>
    105110    <Reference Include="System" />
    106111    <Reference Include="System.Core">
     
    167172    <Compile Include="Implementation\Transformations\ShiftToRangeTransformation.cs" />
    168173    <Compile Include="Implementation\Transformations\Transformation.cs" />
    169     <Compile Include="Implementation\Vectors\DateTimeVector.cs" />
    170     <Compile Include="Implementation\Vectors\StringVector.cs" />
    171     <Compile Include="Implementation\Vectors\DoubleVector.cs" />
    172     <Compile Include="Implementation\Vectors\Vector.cs" />
    173174    <Compile Include="Interfaces\Classification\IClassificationEnsembleModel.cs">
    174175      <SubType>Code</SubType>
     
    183184    <Compile Include="Interfaces\ITransformation.cs" />
    184185    <Compile Include="Interfaces\ITransformationMapper.cs" />
    185     <Compile Include="Interfaces\IVector.cs" />
    186186    <Compile Include="Interfaces\Regression\IConfidenceRegressionModel.cs" />
    187187    <Compile Include="Interfaces\Regression\IConfidenceRegressionSolution.cs" />
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs

    r17365 r17448  
    3030using HEAL.Attic;
    3131
     32using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
     33
    3234namespace HeuristicLab.Problems.DataAnalysis {
    3335  [StorableType("85AE1542-D563-434F-A760-1D181EFC2101")]
     
    162164
    163165      var variables = dataset.VariableNames.Where(variable =>
    164         dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable) || dataset.VariableHasType<DoubleVector> (variable));
     166        dataset.VariableHasType<double>(variable) || dataset.VariableHasType<string>(variable) || dataset.VariableHasType<DoubleVector>(variable));
    165167      var inputVariables = new CheckedItemList<StringValue>(variables.Select(x => new StringValue(x).AsReadOnly()));
    166168      foreach (StringValue x in inputVariables)
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolutionVariableImpactsCalculator.cs

    r17416 r17448  
    3333using HeuristicLab.Random;
    3434
     35using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
     36
    3537namespace HeuristicLab.Problems.DataAnalysis {
    3638  [StorableType("414B25CD-6643-4E42-9EB2-B9A24F5E1528")]
     
    319321          // new var has same empirical distribution but the relation to y is broken
    320322          // prepare a complete column for the dataset
    321           replacementValues = Enumerable.Repeat(new DoubleVector(new[] { double.NaN }), modifiableDataset.Rows).ToList();
     323          replacementValues = Enumerable.Repeat(DoubleVector.Build.Dense(new[] { double.NaN }), modifiableDataset.Rows).ToList();
    322324          // shuffle only the selected rows
    323325          var shuffledValues = rows.Select(r => originalValues[r]).Shuffle(random).ToList();
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataset.cs

    r17365 r17448  
    2727using HEAL.Attic;
    2828
     29using DoubleVector = MathNet.Numerics.LinearAlgebra.Vector<double>;
     30
    2931namespace HeuristicLab.Problems.DataAnalysis {
    3032  [StorableType("55cc9211-2136-41a0-a5bc-0d51e915d1b4")]
     
    3537    IEnumerable<string> DateTimeVariables { get; }
    3638    IEnumerable<string> DoubleVectorVariables { get; }
    37     IEnumerable<string> StringVectorVariables { get; }
    38     IEnumerable<string> DateTimeVectorVariables { get; }
    3939
    4040    bool ContainsVariable(string variablename);
     
    6060    IEnumerable<DoubleVector> GetDoubleVectorValues(string variableName, IEnumerable<int> rows);
    6161    ReadOnlyCollection<DoubleVector> GetReadOnlyDoubleVectorValues(string variableName);
    62 
    63     StringVector GetStringVectorValue(string variableName, int row);
    64     IEnumerable<StringVector> GetStringVectorValues(string variableName);
    65     IEnumerable<StringVector> GetStringVectorValues(string variableName, IEnumerable<int> rows);
    66     ReadOnlyCollection<StringVector> GetReadOnlyStringVectorValues(string variableName);
    67 
    68     DateTimeVector GetDateTimeVectorValue(string variableName, int row);
    69     IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName);
    70     IEnumerable<DateTimeVector> GetDateTimeVectorValues(string variableName, IEnumerable<int> rows);
    71     ReadOnlyCollection<DateTimeVector> GetReadOnlyDateTimeVectorValues(string variableName);
    7262  }
    7363}
  • branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis/3.4/Plugin.cs.frame

    r17184 r17448  
    3939  [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 
    4040  [PluginDependency("HeuristicLab.Random", "3.3")]
     41  [PluginDependency("HeuristicLab.MathNet.Numerics", "4.9.0")]
    4142  public class HeuristicLabProblemsDataAnalysisPlugin : PluginBase {
    4243  }
Note: See TracChangeset for help on using the changeset viewer.