Changeset 13941 for trunk/sources/HeuristicLab.Problems.DataAnalysis
- Timestamp:
- 06/28/16 13:33:17 (8 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Files:
-
- 3 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/HeuristicLab.Problems.DataAnalysis-3.4.csproj
r13766 r13941 132 132 <Compile Include="Implementation\Classification\ConstantClassificationSolution.cs" /> 133 133 <Compile Include="Implementation\Classification\DiscriminantFunctionClassificationSolutionBase.cs" /> 134 <Compile Include="Implementation\Classification\ClassificationModel.cs" /> 134 135 <Compile Include="Implementation\Clustering\ClusteringProblem.cs" /> 135 136 <Compile Include="Implementation\Clustering\ClusteringProblemData.cs" /> 136 137 <Compile Include="Implementation\Clustering\ClusteringSolution.cs" /> 137 138 <Compile Include="Implementation\ConstantModel.cs" /> 139 <Compile Include="Implementation\DataAnalysisModel.cs" /> 138 140 <Compile Include="Implementation\Regression\ConstantRegressionModel.cs" /> 139 141 <Compile Include="Implementation\Regression\ConstantRegressionSolution.cs" /> … … 143 145 </Compile> 144 146 <Compile Include="Implementation\Regression\RegressionEnsembleSolution.cs" /> 147 <Compile Include="Implementation\Regression\RegressionModel.cs" /> 145 148 <Compile Include="Implementation\Regression\RegressionSolutionVariableImpactsCalculator.cs" /> 146 149 <Compile Include="Implementation\TimeSeriesPrognosis\Models\ConstantTimeSeriesPrognosisModel.cs" /> -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r13921 r13941 32 32 [StorableClass] 33 33 [Item("ClassificationEnsembleModel", "A classification model that contains an ensemble of multiple classification models")] 34 public class ClassificationEnsembleModel : NamedItem, IClassificationEnsembleModel {35 public IEnumerable<string> VariablesUsedForPrediction {34 public class ClassificationEnsembleModel : ClassificationModel, IClassificationEnsembleModel { 35 public override IEnumerable<string> VariablesUsedForPrediction { 36 36 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 37 }38 39 public string TargetVariable {40 get { return models.First().TargetVariable; }41 37 } 42 38 … … 56 52 public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { } 57 53 public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models) 58 : base( ) {54 : base(string.Empty) { 59 55 this.name = ItemName; 60 56 this.description = ItemDescription; 61 57 this.models = new List<IClassificationModel>(models); 58 59 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 62 60 } 63 61 … … 66 64 } 67 65 68 #region IClassificationEnsembleModel Members69 66 public void Add(IClassificationModel model) { 67 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 70 68 models.Add(model); 71 69 } 72 70 public void Remove(IClassificationModel model) { 73 71 models.Remove(model); 72 if (!models.Any()) TargetVariable = string.Empty; 74 73 } 75 74 … … 85 84 } 86 85 87 #endregion88 86 89 #region IClassificationModel Members 90 91 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 87 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 92 88 foreach (var estimatedValuesVector in GetEstimatedClassValueVectors(dataset, rows)) { 93 89 // return the class which is most often occuring … … 101 97 } 102 98 103 IClassificationSolution IClassificationModel.CreateClassificationSolution(IClassificationProblemData problemData) {99 public override IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) { 104 100 return new ClassificationEnsembleSolution(models, new ClassificationEnsembleProblemData(problemData)); 105 101 } 106 #endregion 102 103 107 104 } 108 105 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationModel.cs
r13921 r13941 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 {36 public IEnumerable<string> VariablesUsedForPrediction {35 public class DiscriminantFunctionClassificationModel : ClassificationModel, IDiscriminantFunctionClassificationModel { 36 public override IEnumerable<string> VariablesUsedForPrediction { 37 37 get { return model.VariablesUsedForPrediction; } 38 38 } 39 40 public string TargetVariable { get { return model.TargetVariable; } }41 39 42 40 [Storable] … … 79 77 80 78 public DiscriminantFunctionClassificationModel(IRegressionModel model, IDiscriminantFunctionThresholdCalculator thresholdCalculator) 81 : base( ) {79 : base(model.TargetVariable) { 82 80 this.name = ItemName; 83 81 this.description = ItemDescription; 82 84 83 this.model = model; 85 84 this.classValues = new double[0]; … … 121 120 } 122 121 123 public IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) {122 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 124 123 if (!Thresholds.Any() && !ClassValues.Any()) throw new ArgumentException("No thresholds and class values were set for the current classification model."); 125 124 foreach (var x in GetEstimatedValues(dataset, rows)) { … … 141 140 #endregion 142 141 143 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) { 144 147 return new DiscriminantFunctionClassificationSolution(this, new ClassificationProblemData(problemData)); 145 }146 147 public virtual IClassificationSolution CreateClassificationSolution(IClassificationProblemData problemData) {148 return CreateDiscriminantFunctionClassificationSolution(problemData);149 148 } 150 149 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/ConstantModel.cs
r13921 r13941 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 {34 public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } }33 public class ConstantModel : RegressionModel, IClassificationModel, ITimeSeriesPrognosisModel, IStringConvertibleValue { 34 public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 35 35 36 [Storable]37 private readonly string targetVariable;38 public string TargetVariable {39 get { return targetVariable; }40 }41 36 42 37 [Storable] … … 52 47 : base(original, cloner) { 53 48 this.constant = original.constant; 54 this.targetVariable = original.targetVariable;55 49 } 56 50 … … 58 52 59 53 public ConstantModel(double constant, string targetVariable = "Target") 60 : base( ) {54 : base(targetVariable) { 61 55 this.name = ItemName; 62 56 this.description = ItemDescription; 63 57 this.constant = constant; 64 58 this.ReadOnly = true; // changing a constant regression model is not supported 65 this.targetVariable = targetVariable;66 59 } 67 60 68 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 69 62 return rows.Select(row => Constant); 70 63 } … … 76 69 } 77 70 78 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {71 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 79 72 return new ConstantRegressionSolution(this, new RegressionProblemData(problemData)); 80 73 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r13921 r13941 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 { 35 public IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 36 37 [Storable] 38 private readonly string targetVariable; 39 public string TargetVariable { 40 get { return targetVariable; } 41 } 34 public class ConstantRegressionModel : RegressionModel, IStringConvertibleValue { 35 public override IEnumerable<string> VariablesUsedForPrediction { get { return Enumerable.Empty<string>(); } } 42 36 43 37 [Storable] … … 53 47 : base(original, cloner) { 54 48 this.constant = original.constant; 55 this.targetVariable = original.targetVariable;56 49 } 57 50 … … 59 52 60 53 public ConstantRegressionModel(double constant, string targetVariable = "Target") 61 : base( ) {54 : base(targetVariable) { 62 55 this.name = ItemName; 63 56 this.description = ItemDescription; 64 57 this.constant = constant; 65 58 this.ReadOnly = true; // changing a constant regression model is not supported 66 this.targetVariable = targetVariable;67 59 } 68 60 69 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {61 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 70 62 return rows.Select(row => Constant); 71 63 } 72 64 73 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 74 66 return new ConstantRegressionSolution(new ConstantModel(constant), new RegressionProblemData(problemData)); 75 67 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13921 r13941 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 {36 public IEnumerable<string> VariablesUsedForPrediction {35 public sealed class RegressionEnsembleModel : RegressionModel, IRegressionEnsembleModel { 36 public override IEnumerable<string> VariablesUsedForPrediction { 37 37 get { return models.SelectMany(x => x.VariablesUsedForPrediction).Distinct().OrderBy(x => x); } 38 38 } … … 41 41 public IEnumerable<IRegressionModel> Models { 42 42 get { return new List<IRegressionModel>(models); } 43 }44 45 [Storable]46 private readonly string target;47 public string TargetVariable {48 get { return models.First().TargetVariable; }49 43 } 50 44 … … 109 103 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) : this(models, models.Select(m => 1.0)) { } 110 104 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models, IEnumerable<double> modelWeights) 111 : base( ) {105 : base(string.Empty) { 112 106 this.name = ItemName; 113 107 this.description = ItemDescription; 114 108 115 116 109 this.models = new List<IRegressionModel>(models); 117 110 this.modelWeights = new List<double>(modelWeights); 111 112 if (this.models.Any()) this.TargetVariable = this.models.First().TargetVariable; 118 113 } 119 114 120 115 public void Add(IRegressionModel model) { 116 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 117 Add(model, 1.0); 122 118 } 123 119 public void Add(IRegressionModel model, double weight) { 120 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = model.TargetVariable; 121 124 122 models.Add(model); 125 123 modelWeights.Add(weight); … … 131 129 } 132 130 public void AddRange(IEnumerable<IRegressionModel> models, IEnumerable<double> weights) { 131 if (string.IsNullOrEmpty(TargetVariable)) TargetVariable = models.First().TargetVariable; 132 133 133 this.models.AddRange(models); 134 134 modelWeights.AddRange(weights); … … 140 140 models.RemoveAt(index); 141 141 modelWeights.RemoveAt(index); 142 143 if (!models.Any()) TargetVariable = string.Empty; 142 144 OnChanged(); 143 145 } … … 148 150 modelWeights.RemoveAt(index); 149 151 } 152 153 if (!models.Any()) TargetVariable = string.Empty; 150 154 OnChanged(); 151 155 } … … 174 178 } 175 179 176 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {180 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 177 181 double weightsSum = modelWeights.Sum(); 178 182 var summedEstimates = from estimatedValuesVector in GetEstimatedValueVectors(dataset, rows) … … 222 226 223 227 224 public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {228 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 225 229 return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData)); 226 }227 IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {228 return CreateRegressionSolution(problemData);229 230 } 230 231 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/TimeSeriesPrognosis/Models/TimeSeriesPrognosisAutoRegressiveModel.cs
r13921 r13941 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 {33 public IEnumerable<string> VariablesUsedForPrediction {32 public class TimeSeriesPrognosisAutoRegressiveModel : RegressionModel, ITimeSeriesPrognosisModel { 33 public override IEnumerable<string> VariablesUsedForPrediction { 34 34 get { return Enumerable.Empty<string>(); } // what to return here? 35 35 } … … 39 39 [Storable] 40 40 public double Constant { get; private set; } 41 [Storable]42 public string TargetVariable { get; private set; }43 41 44 42 public int TimeOffset { get { return Phi.Length; } } … … 50 48 this.Phi = (double[])original.Phi.Clone(); 51 49 this.Constant = original.Constant; 52 this.TargetVariable = original.TargetVariable;53 50 } 54 51 public override IDeepCloneable Clone(Cloner cloner) { … … 56 53 } 57 54 public TimeSeriesPrognosisAutoRegressiveModel(string targetVariable, double[] phi, double constant) 58 : base( "AR(1) Model") {55 : base(targetVariable, "AR(1) Model") { 59 56 Phi = (double[])phi.Clone(); 60 57 Constant = constant; 61 TargetVariable = targetVariable;62 58 } 63 59 … … 95 91 } 96 92 97 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) {93 public override IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 98 94 var targetVariables = dataset.GetReadOnlyDoubleValues(TargetVariable); 99 95 foreach (int row in rows) { … … 115 111 return new TimeSeriesPrognosisSolution(this, new TimeSeriesPrognosisProblemData(problemData)); 116 112 } 117 public IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) {113 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 118 114 throw new NotSupportedException(); 119 115 }
Note: See TracChangeset
for help on using the changeset viewer.