Changeset 13948 for branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 06/29/16 10:36:52 (9 years ago)
- Location:
- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis
- Files:
-
- 18 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis merged: 13921,13938,13941
- Property svn:mergeinfo changed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r13858 r13948 182 182 <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" /> 183 183 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> 184 <Compile Include="Implementation\Classification\ClassificationModel.cs" /> 184 185 <Compile Include="Implementation\Clustering\ClusteringProblem.cs" /> 185 186 <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" /> 186 187 <Compile Include="Implementation\Clustering\ClusteringSolution.cs" /> 187 188 <Compile Include="Implementation\ConstantModel.cs" /> 189 <Compile Include="Implementation\DataAnalysisModel.cs" /> 188 190 <Compile Include="Implementation\Regression\ConfidenceBoundRegressionSolution.cs" /> 189 191 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> … … 194 196 </Compile> 195 197 <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" /> 198 <Compile Include="Implementation\Regression\RegressionModel.cs" /> 196 199 <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" /> 197 200 <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" /> -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r12509 r13948 32 32 [StorableClass] 33 33 [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 } 35 38 36 39 [Storable] … … 49 52 public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { } 50 53 public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models) 51 : base( ) {54 : base(string.Empty) { 52 55 this.name = ItemName; 53 56 this.description = ItemDescription; 54 57 this.models = new List<IClassificationModel>(models); 58 59 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 55 60 } 56 61 … … 59 64 } 60 65 61 #region IClassificationEnsembleModel Members62 66 public void Add(IClassificationModel model) { 67 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 63 68 models.Add(model); 64 69 } 65 70 public void Remove(IClassificationModel model) { 66 71 models.Remove(model); 72 if (!models.Any()) TargetVariable = string.Empty; 67 73 } 68 74 … … 78 84 } 79 85 80 #endregion81 86 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) { 85 88 foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) { 86 89 // return the class which is most often occuring … … 94 97 } 95 98 96 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {99 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 97 100 return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData)); 98 101 } 99 #endregion 102 103 100 104 } 101 105 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r12509 r13948 33 33 [StorableClass] 34 34 [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 36 40 [Storable] 37 41 private IRegressionModel model; … … 73 77 74 78 public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator) 75 : base( ) {79 : base(model.TargetVariable) { 76 80 this.name = ItemName; 77 81 this.description = ItemDescription; 82 78 83 this.model = model; 79 84 this.classValues = new double[0]; … … 115 120 } 116 121 117 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {122 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 118 123 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 119 124 foreach (var x in GetEstimatedValues(dataset, rows)) { … … 135 140 #endregion 136 141 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) { 138 147 return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData)); 139 }140 141 public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {142 return CreateDiscriminantFunctionClassificationSolution(problemData);143 148 } 144 149 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs
r13154 r13948 31 31 [StorableClass] 32 32 [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 34 37 [Storable] 35 private double constant;38 private readonly double constant; 36 39 public double Constant { 37 40 get { return constant; } … … 45 48 this.constant = original.constant; 46 49 } 50 47 51 public override IDeepCloneable Clone(Cloner cloner) { return new ConstantModel(this, cloner); } 48 52 49 public ConstantModel(double constant )50 : base( ) {53 public ConstantModel(double constant, string targetVariable = "Target") 54 : base(targetVariable) { 51 55 this.name = ItemName; 52 56 this.description = ItemDescription; … … 55 59 } 56 60 57 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 58 62 return rows.Select(row => Constant); 59 63 } … … 65 69 } 66 70 67 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {71 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 68 72 return new ConstantRegressionSolution(this, new RegressionProblemData(problemData)); 69 73 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs
r13831 r13948 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 111 111 protected override void DeregisterItemEvents(IEnumerable<IResult> items) { } 112 112 113 public virtual IEnumerable<string> GetUsedVariablesForPrediction() {114 return this.ProblemData.AllowedInputVariables;115 }116 117 113 #region INamedItem Members 118 114 [Storable] -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r13100 r13948 32 32 [Item("Constant Regression Model", "A model that always returns the same constant value regardless of the presented input data.")] 33 33 [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 35 37 [Storable] 36 38 private double constant; … … 46 48 this.constant = original.constant; 47 49 } 50 48 51 public override IDeepCloneable Clone(Cloner cloner) { return new ConstantRegressionModel(this, cloner); } 49 52 50 public ConstantRegressionModel(double constant )51 : base( ) {53 public ConstantRegressionModel(double constant, string targetVariable = "Target") 54 : base(targetVariable) { 52 55 this.name = ItemName; 53 56 this.description = ItemDescription; … … 56 59 } 57 60 58 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 59 62 return rows.Select(row => Constant); 60 63 } 61 64 62 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 63 66 return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData)); 64 67 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13715 r13948 33 33 [StorableClass] 34 34 [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 } 36 39 37 40 private List<IRegressionModel> models; … … 100 103 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { } 101 104 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights) 102 : base( ) {105 : base(string.Empty) { 103 106 this.name = ItemName; 104 107 this.description = ItemDescription; 105 108 106 107 109 this.models = new List<IRegressionModel>(models); 108 110 this.modelWeights = new List<double>(modelWeights); 111 112 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 109 113 } 110 114 111 115 public void Add(IRegressionModel model) { 116 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 112 117 Add(model, 1.0); 113 118 } 114 119 public void Add(IRegressionModel model, double weight) { 120 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 115 122 models.Add(model); 116 123 modelWeights.Add(weight); … … 122 129 } 123 130 public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) { 131 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable; 132 124 133 this.models.AddRange(models); 125 134 modelWeights.AddRange(weights); … … 131 140 models.RemoveAt(index); 132 141 modelWeights.RemoveAt(index); 142 143 if (!models.Any()) TargetVariable = string.Empty; 133 144 OnChanged(); 134 145 } … … 139 150 modelWeights.RemoveAt(index); 140 151 } 152 153 if (!models.Any()) TargetVariable = string.Empty; 141 154 OnChanged(); 142 155 } … … 165 178 } 166 179 167 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {180 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 168 181 double weightsSum = modelWeights.Sum(); 169 182 var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows) … … 213 226 214 227 215 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {228 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 216 229 return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData)); 217 }218 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {219 return CreateRegressionSolution(problemData);220 230 } 221 231 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r12509 r13948 30 30 [StorableClass] 31 31 [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 33 37 [Storable] 34 38 public double[] Phi { get; private set; } 35 39 [Storable] 36 40 public double Constant { get; private set; } 37 [Storable]38 public string TargetVariable { get; private set; }39 41 40 42 public int TimeOffset { get { return Phi.Length; } } … … 46 48 this.Phi = (double[])original.Phi.Clone(); 47 49 this.Constant = original.Constant; 48 this.TargetVariable = original.TargetVariable;49 50 } 50 51 public override IDeepCloneable Clone(Cloner cloner) { … … 52 53 } 53 54 public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant) 54 : base( "AR(1) Model") {55 : base(targetVariable, "AR(1) Model") { 55 56 Phi = (double[])phi.Clone(); 56 57 Constant = constant; 57 TargetVariable = targetVariable;58 58 } 59 59 … … 91 91 } 92 92 93 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {93 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 94 94 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 95 95 foreach (int row in rows) { … … 111 111 return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData)); 112 112 } 113 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {113 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 114 114 throw new NotSupportedException(); 115 115 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Classification/IClassificationModel.cs
r12509 r13948 25 25 IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows); 26 26 IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData); 27 string TargetVariable { get; } 27 28 } 28 29 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisModel.cs
r12012 r13948 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Core; 23 24 24 25 namespace HeuristicLab.Problems.DataAnalysis { 25 26 public interface IDataAnalysisModel : INamedItem { 27 IEnumerable<string> VariablesUsedForPrediction { get; } 26 28 } 27 29 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisSolution.cs
r13831 r13948 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using HeuristicLab.Common; 25 24 using HeuristicLab.Core; … … 29 28 IDataAnalysisModel Model { get; } 30 29 IDataAnalysisProblemData ProblemData { get; set; } 31 IEnumerable<string> GetUsedVariablesForPrediction();32 30 33 31 event EventHandler ModelChanged; -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDependencyCalculator.cs
r12012 r13948 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 … … 29 30 30 31 double Calculate(IEnumerable<double> originalValues, IEnumerable<double> estimatedValues, out OnlineCalculatorError errorState); 32 double Calculate(IEnumerable<Tuple<double, double>> values, out OnlineCalculatorError errorState); 31 33 } 32 34 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/Regression/IRegressionModel.cs
r13823 r13948 25 25 IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 26 26 IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData); 27 string TargetVariable { get; } 27 28 } 28 29 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/HoeffdingsDependenceCalculator.cs
r12012 r13948 41 41 if (errorState != OnlineCalculatorError.None) return double.NaN; 42 42 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); 43 47 } 44 48 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRDependenceCalculator.cs
r12492 r13948 35 35 return OnlinePearsonsRCalculator.Calculate(originalValues, estimatedValues, out errorState); 36 36 } 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 } 37 47 } 38 48 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/PearsonsRSquaredDependenceCalculator.cs
r12641 r13948 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 … … 35 36 return r * r; 36 37 } 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 } 37 49 } 38 50 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/DependencyCalculator/SpearmansRankCorrelationCoefficientCalculator.cs
r12817 r13948 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 33 34 34 35 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); 36 40 } 37 41 … … 50 54 return rs; 51 55 } 56 57 52 58 } 53 59 }
Note: See TracChangeset
for help on using the changeset viewer.