- Timestamp:
- 03/14/16 18:20:44 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r13698 r13700 33 33 [StorableClass] 34 34 [Item("RegressionEnsembleModel", "A regression model that contains an ensemble of multiple regression models")] 35 public class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel {35 public sealed class RegressionEnsembleModel : NamedItem, IRegressionEnsembleModel { 36 36 37 37 private List<IRegressionModel> models; … … 46 46 } 47 47 48 [Storable] 49 private bool averageModelEstimates = true; 50 public bool AverageModelEstimates { 51 get { return averageModelEstimates; } 52 set { 53 if (averageModelEstimates != value) { 54 averageModelEstimates = value; 55 OnAverageModelEstimatesChanged(); 56 } 57 } 58 } 59 48 60 #region backwards compatiblity 3.3.5 49 61 [Storable(Name = "models", AllowOneWay = true)] … … 54 66 55 67 [StorableConstructor] 56 pr otectedRegressionEnsembleModel(bool deserializing) : base(deserializing) { }57 pr otectedRegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner)68 private RegressionEnsembleModel(bool deserializing) : base(deserializing) { } 69 private RegressionEnsembleModel(RegressionEnsembleModel original, Cloner cloner) 58 70 : base(original, cloner) { 59 this.models = original.Models.Select(m => cloner.Clone(m)).ToList(); 71 this.models = original.Models.Select(cloner.Clone).ToList(); 72 this.averageModelEstimates = original.averageModelEstimates; 73 } 74 public override IDeepCloneable Clone(Cloner cloner) { 75 return new RegressionEnsembleModel(this, cloner); 60 76 } 61 77 … … 68 84 } 69 85 70 public override IDeepCloneable Clone(Cloner cloner) {71 return new RegressionEnsembleModel(this, cloner);72 }73 74 86 #region IRegressionEnsembleModel Members 75 87 public void Add(IRegressionModel model) { 76 88 models.Add(model); 77 89 } 90 78 91 public void Remove(IRegressionModel model) { 79 92 models.Remove(model); … … 99 112 int currentRow = rowsEnumerator.Current; 100 113 101 var filteredEstimates = models.Zip(estimatedValuesEnumerators.Current, 102 (m, e) => new { Model = m, EstimatedValue = e }).Where(f => modelSelectionPredicate(currentRow, f.Model)); 114 var filteredEstimates = models.Zip(estimatedValuesEnumerators.Current, (m, e) => new { Model = m, EstimatedValue = e }) 115 .Where(f => modelSelectionPredicate(currentRow, f.Model)) 116 .Select(f => f.EstimatedValue).DefaultIfEmpty(double.NaN); 103 117 104 yield return filteredEstimates.Select(f => f.EstimatedValue).DefaultIfEmpty(double.NaN).Average();118 yield return AggregateEstimatedValues(filteredEstimates); 105 119 } 120 } 121 122 private double AggregateEstimatedValues(IEnumerable<double> estimatedValuesVector) { 123 if (AverageModelEstimates) 124 return estimatedValuesVector.Average(); 125 else 126 return estimatedValuesVector.Sum(); 127 } 128 129 public event EventHandler AverageModelEstimatesChanged; 130 private void OnAverageModelEstimatesChanged() { 131 var handler = AverageModelEstimatesChanged; 132 if (handler != null) 133 handler(this, EventArgs.Empty); 106 134 } 107 135 #endregion … … 110 138 public IEnumerable<double> GetEstimatedValues(IDataset dataset, IEnumerable<int> rows) { 111 139 foreach (var estimatedValuesVector in GetEstimatedValueVectors(dataset, rows)) { 112 yield return estimatedValuesVector.Average();140 yield return AggregateEstimatedValues(estimatedValuesVector); 113 141 } 114 142 }
Note: See TracChangeset
for help on using the changeset viewer.