Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/04/19 08:22:42 (6 years ago)
Author:
gkronber
Message:

#2925 merged r16661:16890 from trunk to branch

Location:
branches/2925_AutoDiffForDynamicalModels
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/2925_AutoDiffForDynamicalModels

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4

  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Dataset.cs

    r16662 r16892  
    2525using System.Collections.ObjectModel;
    2626using System.Linq;
     27using HEAL.Attic;
    2728using HeuristicLab.Common;
    2829using HeuristicLab.Core;
    2930using HeuristicLab.Data;
    30 using HEAL.Attic;
    3131
    3232namespace HeuristicLab.Problems.DataAnalysis {
     
    115115    }
    116116
     117    public static Dataset FromRowData(IEnumerable<string> variableNames, double[,] data) {
     118      var colWise = new List<IList>(data.GetLength(1));
     119      for (var col = 0; col < data.GetLength(1); col++) {
     120        var column = new List<double>(data.GetLength(0));
     121        for (var row = 0; row < data.GetLength(0); row++) {
     122          column.Add(data[row, col]);
     123        }
     124        colWise.Add(column);
     125      }
     126      return new Dataset(variableNames, colWise);
     127    }
     128
     129    public static Dataset FromRowData(IEnumerable<string> variableNames, IEnumerable<IList> data) {
     130      var vnames = variableNames.ToList();
     131      var transposed = new List<IList>();
     132      var iter = data.GetEnumerator();
     133      if (!iter.MoveNext()) throw new ArgumentException("Data does not contain any rows", nameof(data));
     134      for (var i = 0; i < iter.Current.Count; i++) {
     135        if (i >= vnames.Count) throw new ArgumentException("There are more variables in data, than variable names.", nameof(variableNames));
     136        if (iter.Current[i] == null) throw new ArgumentException("Null values are not supported.", nameof(data));
     137        if (!IsAllowedType(iter.Current[i].GetType())) throw new ArgumentException("Data contains types that are not allowed.", nameof(data));
     138        if (iter.Current[i] is double d)
     139          transposed.Add(new List<double>() { d });
     140        else if (iter.Current[i] is DateTime dt)
     141          transposed.Add(new List<DateTime>() { dt });
     142        else if (iter.Current[i] is string s)
     143          transposed.Add(new List<string>() { s });
     144        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()));
     145      }
     146      if (transposed.Count < vnames.Count) throw new ArgumentException("There are less variables in data, than variable names.", nameof(variableNames));
     147      while (iter.MoveNext()) {
     148        for (var i = 0; i < iter.Current.Count; i++)
     149          if (transposed[i].Add(iter.Current[i]) < 0)
     150            throw new ArgumentException(string.Format("Variable {0} has invalid value ({1})", vnames[i], iter.Current[i]), nameof(data));
     151      }
     152      return new Dataset(vnames, transposed);
     153    }
     154
    117155    public ModifiableDataset ToModifiable() {
    118156      return new ModifiableDataset(variableNames, variableNames.Select(v => variableValues[v]), true);
     
    133171    #region Backwards compatible code, remove with 3.5
    134172    private double[,] storableData;
    135     //name alias used to suppport backwards compatibility
    136     [Storable(Name = "data", AllowOneWay = true)]
     173    //name alias used to support backwards compatibility
     174    [Storable(OldName = "data")]
    137175    private double[,] StorableData { set { storableData = value; } }
    138176
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r16662 r16892  
    244244    <Compile Include="OnlineCalculators\OnlineTheilsUStatisticCalculator.cs" />
    245245    <Compile Include="OnlineCalculators\OnlineWeightedDirectionalSymmetryCalculator.cs" />
     246    <Compile Include="OnlineCalculators\OnlineWeightedClassificationMeanSquaredErrorCalculator.cs" />
    246247    <Compile Include="Plugin.cs" />
    247248    <Compile Include="Implementation\Classification\ThresholdCalculators\AccuracyMaximizationThresholdCalculator.cs" />
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationModel.cs

    r16662 r16892  
    7575      var classificationProblemData = problemData as IClassificationProblemData;
    7676      if (classificationProblemData == null)
    77         throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     77        throw new ArgumentException("The problem data is not compatible with this classification model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
    7878      return IsProblemDataCompatible(classificationProblemData, out errorMessage);
    7979    }
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r16662 r16892  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HEAL.Attic;
    2526using HeuristicLab.Common;
    2627using HeuristicLab.Core;
    27 using HEAL.Attic;
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis {
     
    121121
    122122    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     123      var estimatedValues = GetEstimatedValues(dataset, rows);
     124      return GetEstimatedClassValues(estimatedValues);
     125    }
     126
     127    public virtual IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues) {
    123128      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    124       foreach (var x in GetEstimatedValues(dataset, rows)) {
     129      foreach (var x in estimatedValues) {
    125130        int classIndex = 0;
    126131        // find first threshold value which is larger than x => class index = threshold index + 1
     
    132137      }
    133138    }
     139
    134140    #region events
    135141    public event EventHandler ThresholdsChanged;
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs

    r16662 r16892  
    9898        return IsProblemDataCompatible(classificationProblemData, out errorMessage);
    9999
    100       throw new ArgumentException("The problem data is not a regression nor a classification problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     100      throw new ArgumentException("The problem data is compatible with this model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
    101101    }
    102102
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Interval.cs

    r16662 r16892  
    167167    }
    168168    public static Interval Cosine(Interval a) {
    169       return Interval.Sine(Interval.Subtract(a, new Interval(Math.PI / 2, Math.PI / 2)));
     169      return Interval.Sine(Interval.Add(a, new Interval(Math.PI / 2, Math.PI / 2)));
    170170    }
    171171    public static Interval Tangens(Interval a) {
    172172      return Interval.Divide(Interval.Sine(a), Interval.Cosine(a));
     173    } 
     174    public static Interval HyperbolicTangent(Interval a) {
     175      return new Interval(Math.Tanh(a.LowerBound), Math.Tanh(a.UpperBound));
    173176    }
    174177
     
    203206      if (a.UpperBound <= 0) return new Interval(a.UpperBound * a.UpperBound, a.LowerBound * a.LowerBound);     // interval is negative
    204207      else if (a.LowerBound >= 0) return new Interval(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound); // interval is positive
    205       else return new Interval(0, Math.Max(a.LowerBound*a.LowerBound, a.UpperBound*a.UpperBound)); // interval goes over zero
     208      else return new Interval(0, Math.Max(a.LowerBound * a.LowerBound, a.UpperBound * a.UpperBound)); // interval goes over zero
    206209    }
    207210
     
    224227    public static Interval CubicRoot(Interval a) {
    225228      if (a.LowerBound < 0) return new Interval(double.NaN, double.NaN);
    226       return new Interval(Math.Pow(a.LowerBound, 1.0/3), Math.Pow(a.UpperBound, 1.0/3));
     229      return new Interval(Math.Pow(a.LowerBound, 1.0 / 3), Math.Pow(a.UpperBound, 1.0 / 3));
    227230    }
    228231    #endregion
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r16662 r16892  
    7373
    7474    #region backwards compatiblity 3.3.5
    75     [Storable(Name = "models", AllowOneWay = true)]
     75    [Storable(OldName = "models")]
    7676    private List<IRegressionModel> OldStorableModels {
    7777      set { models = value; }
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionModel.cs

    r16662 r16892  
    7676      var regressionProblemData = problemData as IRegressionProblemData;
    7777      if (regressionProblemData == null)
    78         throw new ArgumentException("The problem data is not a regression problem data. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
     78        throw new ArgumentException("The problem data is not compatible with this regression model. Instead a " + problemData.GetType().GetPrettyName() + " was provided.", "problemData");
    7979      return IsProblemDataCompatible(regressionProblemData, out errorMessage);
    8080    }
  • branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IDiscriminantFunctionClassificationModel.cs

    r16662 r16892  
    3434    void SetThresholdsAndClassValues(IEnumerable<double> thresholds, IEnumerable<double> classValues);
    3535    IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows);
     36    IEnumerable<double> GetEstimatedClassValues(IEnumerable<double> estimatedValues);
    3637
    3738    event EventHandler ThresholdsChanged;
Note: See TracChangeset for help on using the changeset viewer.