Ignore:
Timestamp:
06/29/16 10:36:52 (5 years ago)
Author:
pfleck
Message:

#2597

  • Merged recent trunk changes.
  • Adapted VariablesUsedForPrediction property for RegressionSolutionTargetResponseGradientView.
  • Fixed a reference (.dll to project ref).
Location:
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis
Files:
18 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis

  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj

    r13858 r13948  
    182182    <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" />
    183183    <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" />
     184    <Compile Include="Implementation\Classification\ClassificationModel.cs" />
    184185    <Compile Include="Implementation\Clustering\ClusteringProblem.cs" />
    185186    <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" />
    186187    <Compile Include="Implementation\Clustering\ClusteringSolution.cs" />
    187188    <Compile Include="Implementation\ConstantModel.cs" />
     189    <Compile Include="Implementation\DataAnalysisModel.cs" />
    188190    <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" />
    189191    <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" />
     
    194196    </Compile>
    195197    <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" />
     198    <Compile Include="Implementation\Regression\RegressionModel.cs" />
    196199    <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" />
    197200    <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" />
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r12509 r13948  
    3232  [StorableClass]
    3333  [Item("ClassificationEnsembleModel", "A classification model that contains an ensemble of multiple classification models")]
    34   public class ClassificationEnsembleModel : NamedItem, IClassificationEnsembleModel {
     34  public class ClassificationEnsembleModel : ClassificationModel, IClassificationEnsembleModel {
     35    public override IEnumerable<string> VariablesUsedForPrediction {
     36      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     37    }
    3538
    3639    [Storable]
     
    4952    public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { }
    5053    public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models)
    51       : base() {
     54      : base(string.Empty) {
    5255      this.name = ItemName;
    5356      this.description = ItemDescription;
    5457      this.models = new List<IClassificationModel>(models);
     58
     59      if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable;
    5560    }
    5661
     
    5964    }
    6065
    61     #region IClassificationEnsembleModel Members
    6266    public void Add(IClassificationModel model) {
     67      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
    6368      models.Add(model);
    6469    }
    6570    public void Remove(IClassificationModel model) {
    6671      models.Remove(model);
     72      if (!models.Any()) TargetVariable = string.Empty;
    6773    }
    6874
     
    7884    }
    7985
    80     #endregion
    8186
    82     #region IClassificationModel Members
    83 
    84     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     87    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    8588      foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) {
    8689        // return the class which is most often occuring
     
    9497    }
    9598
    96     IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {
     99    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    97100      return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData));
    98101    }
    99     #endregion
     102
     103
    100104  }
    101105}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs

    r12509 r13948  
    3333  [StorableClass]
    3434  [Item("DiscriminantFunctionClassificationModel", "Represents a classification model that uses a discriminant function and classification thresholds.")]
    35   public class DiscriminantFunctionClassificationModel : NamedItem, IDiscriminantFunctionClassificationModel {
     35  public class DiscriminantFunctionClassificationModel : ClassificationModel, IDiscriminantFunctionClassificationModel {
     36    public override IEnumerable<string> VariablesUsedForPrediction {
     37      get { return model.VariablesUsedForPrediction; }
     38    }
     39
    3640    [Storable]
    3741    private IRegressionModel model;
     
    7377
    7478    public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator)
    75       : base() {
     79      : base(model.TargetVariable) {
    7680      this.name = ItemName;
    7781      this.description = ItemDescription;
     82
    7883      this.model = model;
    7984      this.classValues = new double[0];
     
    115120    }
    116121
    117     public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
     122    public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {
    118123      if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model.");
    119124      foreach (var x in GetEstimatedValues(dataset, rows)) {
     
    135140    #endregion
    136141
    137     public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(IClassificationProblemData problemData) {
     142    public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
     143      return CreateDiscriminantFunctionClassificationSolution(problemData);
     144    }
     145    public virtual IDiscriminantFunctionClassificationSolution CreateDiscriminantFunctionClassificationSolution(
     146      IClassificationProblemData problemData) {
    138147      return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData));
    139     }
    140 
    141     public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {
    142       return CreateDiscriminantFunctionClassificationSolution(problemData);
    143148    }
    144149  }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs

    r13154 r13948  
    3131  [StorableClass]
    3232  [Item("Constant Model", "A model that always returns the same constant value regardless of the presented input data.")]
    33   public class ConstantModel : NamedItem, IRegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
     33  public class ConstantModel : RegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue {
     34    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
     35
     36
    3437    [Storable]
    35     private double constant;
     38    private readonly double constant;
    3639    public double Constant {
    3740      get { return constant; }
     
    4548      this.constant = original.constant;
    4649    }
     50
    4751    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantModel(this, cloner); }
    4852
    49     public ConstantModel(double constant)
    50       : base() {
     53    public ConstantModel(double constant, string targetVariable = "Target")
     54      : base(targetVariable) {
    5155      this.name = ItemName;
    5256      this.description = ItemDescription;
     
    5559    }
    5660
    57     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     61    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    5862      return rows.Select(row => Constant);
    5963    }
     
    6569    }
    6670
    67     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     71    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    6872      return new ConstantRegressionSolution(this, new RegressionProblemData(problemData));
    6973    }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs

    r13831 r13948  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    111111    protected override void DeregisterItemEvents(IEnumerable<IResult> items) { }
    112112
    113     public virtual IEnumerable<string> GetUsedVariablesForPrediction() {
    114       return this.ProblemData.AllowedInputVariables;
    115     }
    116 
    117113    #region INamedItem Members
    118114    [Storable]
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs

    r13100 r13948  
    3232  [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")]
    3333  [Obsolete]
    34   public class ConstantRegressionModel : NamedItem, IRegressionModel, IStringConvertibleValue {
     34  public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue {
     35    public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }
     36
    3537    [Storable]
    3638    private double constant;
     
    4648      this.constant = original.constant;
    4749    }
     50
    4851    public override IDeepCloneable Clone(Cloner cloner) { return new ConstantRegressionModel(this, cloner); }
    4952
    50     public ConstantRegressionModel(double constant)
    51       : base() {
     53    public ConstantRegressionModel(double constant, string targetVariable = "Target")
     54      : base(targetVariable) {
    5255      this.name = ItemName;
    5356      this.description = ItemDescription;
     
    5659    }
    5760
    58     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     61    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    5962      return rows.Select(row => Constant);
    6063    }
    6164
    62     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     65    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    6366      return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData));
    6467    }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r13715 r13948  
    3333  [StorableClass]
    3434  [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")]
    35   public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {
     35  public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel {
     36    public override IEnumerable<string> VariablesUsedForPrediction {
     37      get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); }
     38    }
    3639
    3740    private List<IRegressionModel> models;
     
    100103    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { }
    101104    public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights)
    102       : base() {
     105      : base(string.Empty) {
    103106      this.name = ItemName;
    104107      this.description = ItemDescription;
    105108
    106 
    107109      this.models = new List<IRegressionModel>(models);
    108110      this.modelWeights = new List<double>(modelWeights);
     111
     112      if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable;
    109113    }
    110114
    111115    public void Add(IRegressionModel model) {
     116      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
    112117      Add(model, 1.0);
    113118    }
    114119    public void Add(IRegressionModel model, double weight) {
     120      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable;
     121
    115122      models.Add(model);
    116123      modelWeights.Add(weight);
     
    122129    }
    123130    public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) {
     131      if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable;
     132
    124133      this.models.AddRange(models);
    125134      modelWeights.AddRange(weights);
     
    131140      models.RemoveAt(index);
    132141      modelWeights.RemoveAt(index);
     142
     143      if (!models.Any()) TargetVariable = string.Empty;
    133144      OnChanged();
    134145    }
     
    139150        modelWeights.RemoveAt(index);
    140151      }
     152
     153      if (!models.Any()) TargetVariable = string.Empty;
    141154      OnChanged();
    142155    }
     
    165178    }
    166179
    167     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     180    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    168181      double weightsSum = modelWeights.Sum();
    169182      var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)
     
    213226
    214227
    215     public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     228    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    216229      return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData));
    217     }
    218     IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
    219       return CreateRegressionSolution(problemData);
    220230    }
    221231  }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs

    r12509 r13948  
    3030  [StorableClass]
    3131  [Item("Autoregressive TimeSeries Model", "A linear autoregressive time series model used to predict future values.")]
    32   public class TimeSeriesPrognosisAutoRegressiveModel : NamedItem, ITimeSeriesPrognosisModel {
     32  public class TimeSeriesPrognosisAutoRegressiveModel : RegressionModel, ITimeSeriesPrognosisModel {
     33    public override IEnumerable<string> VariablesUsedForPrediction {
     34      get { return Enumerable.Empty<string>(); } // what to return here?
     35    }
     36
    3337    [Storable]
    3438    public double[] Phi { get; private set; }
    3539    [Storable]
    3640    public double Constant { get; private set; }
    37     [Storable]
    38     public string TargetVariable { get; private set; }
    3941
    4042    public int TimeOffset { get { return Phi.Length; } }
     
    4648      this.Phi = (double[])original.Phi.Clone();
    4749      this.Constant = original.Constant;
    48       this.TargetVariable = original.TargetVariable;
    4950    }
    5051    public override IDeepCloneable Clone(Cloner cloner) {
     
    5253    }
    5354    public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant)
    54       : base("AR(1) Model") {
     55      : base(targetVariable, "AR(1) Model") {
    5556      Phi = (double[])phi.Clone();
    5657      Constant = constant;
    57       TargetVariable = targetVariable;
    5858    }
    5959
     
    9191    }
    9292
    93     public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
     93    public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {
    9494      var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable);
    9595      foreach (int row in rows) {
     
    111111      return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData));
    112112    }
    113     public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
     113    public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    114114      throw new NotSupportedException();
    115115    }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs

    r12509 r13948  
    2525    IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows);
    2626    IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData);
     27    string TargetVariable { get; }
    2728  }
    2829}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs

    r12012 r13948  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using HeuristicLab.Core;
    2324
    2425namespace HeuristicLab.Problems.DataAnalysis {
    2526  public interface IDataAnalysisModel : INamedItem {
     27    IEnumerable<string> VariablesUsedForPrediction { get; }
    2628  }
    2729}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisSolution.cs

    r13831 r13948  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2121
    2222using System;
    23 using System.Collections.Generic;
    2423using HeuristicLab.Common;
    2524using HeuristicLab.Core;
     
    2928    IDataAnalysisModel Model { get; }
    3029    IDataAnalysisProblemData ProblemData { get; set; }
    31     IEnumerable<string> GetUsedVariablesForPrediction();
    3230
    3331    event EventHandler ModelChanged;
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs

    r12012 r13948  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324
     
    2930
    3031    double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState);
     32    double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState);
    3133  }
    3234}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs

    r13823 r13948  
    2525    IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows);
    2626    IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData);
     27    string TargetVariable { get; }
    2728  }
    2829
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs

    r12012 r13948  
    4141      if (errorState != OnlineCalculatorError.None) return double.NaN;
    4242      return d;
     43    }
     44
     45    public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) {
     46      return HoeffD(values.Select(v => v.Item1), values.Select(v => v.Item2), out errorState);
    4347    }
    4448
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs

    r12492 r13948  
    3535      return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState);
    3636    }
     37
     38    public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) {
     39      var calculator = new OnlinePearsonsRCalculator();
     40      foreach (var tuple in values) {
     41        calculator.Add(tuple.Item1, tuple.Item2);
     42        if (calculator.ErrorState != OnlineCalculatorError.None) break;
     43      }
     44      errorState = calculator.ErrorState;
     45      return calculator.R;
     46    }
    3747  }
    3848}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs

    r12641 r13948  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324
     
    3536      return r * r;
    3637    }
     38
     39    public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) {
     40      var calculator = new OnlinePearsonsRCalculator();
     41      foreach (var tuple in values) {
     42        calculator.Add(tuple.Item1, tuple.Item2);
     43        if (calculator.ErrorState != OnlineCalculatorError.None) break;
     44      }
     45      errorState = calculator.ErrorState;
     46      var r = calculator.R;
     47      return r * r;
     48    }
    3749  }
    3850}
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs

    r12817 r13948  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    3334
    3435    public double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState) {
    35       return SpearmansRankCorrelationCoefficientCalculator.CalculateSpearmansRank(originalValues, estimatedValues, out errorState);
     36      return CalculateSpearmansRank(originalValues, estimatedValues, out errorState);
     37    }
     38    public double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState) {
     39      return CalculateSpearmansRank(values.Select(v => v.Item1), values.Select(v => v.Item2), out errorState);
    3640    }
    3741
     
    5054      return rs;
    5155    }
     56
     57
    5258  }
    5359}
Note: See TracChangeset for help on using the changeset viewer.