- Timestamp:
- 07/08/16 14:37:15 (9 years ago)
- Location:
- stable
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13826,13921-13922,13941,13992-13993,14000
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis merged: 13826,13921,13941,13992-13993,14000
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/ConstantRegressionModel.cs
r13156 r14027 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) 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) {63 return new ConstantRegressionSolution(new ConstantModel(constant ), new RegressionProblemData(problemData));65 public override IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData) { 66 return new ConstantRegressionSolution(new ConstantModel(constant, TargetVariable), new RegressionProblemData(problemData)); 64 67 } 65 68 -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13976 r14027 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 } -
stable/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionModel.cs
r13941 r14027 56 56 } 57 57 58 [StorableHook(HookType.AfterDeserialization)] 59 private void AfterDeserialization() { 60 // BackwardsCompatibility3.3 61 #region Backwards compatible code, remove with 3.4 62 targetVariable = string.Empty; 63 #endregion 64 } 58 65 public abstract IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows); 59 66 public abstract IRegressionSolution CreateRegressionSolution(IRegressionProblemData problemData);
Note: See TracChangeset
for help on using the changeset viewer.