- Timestamp:
- 07/06/11 21:13:34 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r5809 r6520 58 58 #region IRegressionEnsembleModel Members 59 59 60 public void Add(IRegressionModel model) { 61 models.Add(model); 62 } 63 60 64 public IEnumerable<IEnumerable<double>> GetEstimatedValueVectors(Dataset dataset, IEnumerable<int> rows) { 61 65 var estimatedValuesEnumerators = (from model in models -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r6302 r6520 64 64 trainingPartitions = new Dictionary<IRegressionModel, IntRange>(); 65 65 testPartitions = new Dictionary<IRegressionModel, IntRange>(); 66 foreach (var model in models) { 67 trainingPartitions[model] = (IntRange)problemData.TrainingPartition.Clone(); 68 testPartitions[model] = (IntRange)problemData.TestPartition.Clone(); 69 } 66 AddModelsAndParitions(models, 67 from m in models select (IntRange)problemData.TrainingPartition.Clone(), 68 from m in models select (IntRange)problemData.TestPartition.Clone()); 70 69 RecalculateResults(); 71 70 } … … 75 74 this.trainingPartitions = new Dictionary<IRegressionModel, IntRange>(); 76 75 this.testPartitions = new Dictionary<IRegressionModel, IntRange>(); 77 var modelEnumerator = models.GetEnumerator(); 78 var trainingPartitionEnumerator = trainingPartitions.GetEnumerator(); 79 var testPartitionEnumerator = testPartitions.GetEnumerator(); 80 while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) { 81 this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone(); 82 this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone(); 83 } 84 if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) { 85 throw new ArgumentException(); 86 } 76 AddModelsAndParitions(models, trainingPartitions, testPartitions); 87 77 RecalculateResults(); 88 78 } … … 160 150 return estimatedValues.DefaultIfEmpty(double.NaN).Average(); 161 151 } 152 153 154 public void AddModelsAndParitions(IEnumerable<IRegressionSolution> solutions) { 155 foreach (var solution in solutions) { 156 var ensembleSolution = solution as RegressionEnsembleSolution; 157 if (ensembleSolution != null) { 158 var data = from m in ensembleSolution.Model.Models 159 let train = ensembleSolution.trainingPartitions[m] 160 let test = ensembleSolution.testPartitions[m] 161 select new { m, train, test }; 162 163 foreach (var d in data) { 164 Model.Add(d.m); 165 trainingPartitions[d.m] = (IntRange)d.train.Clone(); 166 testPartitions[d.m] = (IntRange)d.test.Clone(); 167 } 168 } else { 169 Model.Add(solution.Model); 170 trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone(); 171 testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone(); 172 } 173 } 174 175 RecalculateResults(); 176 } 177 178 private void AddModelsAndParitions(IEnumerable<IRegressionModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) { 179 var modelEnumerator = models.GetEnumerator(); 180 var trainingPartitionEnumerator = trainingPartitions.GetEnumerator(); 181 var testPartitionEnumerator = testPartitions.GetEnumerator(); 182 183 while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) { 184 this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone(); 185 this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone(); 186 } 187 if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) { 188 throw new ArgumentException(); 189 } 190 } 162 191 } 163 192 }
Note: See TracChangeset
for help on using the changeset viewer.