Changeset 7215 for branches/HeuristicLab.Hive.Azure/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine
- Timestamp:
- 12/20/11 13:54:57 (13 years ago)
- Location:
- branches/HeuristicLab.Hive.Azure
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Hive.Azure
- Property svn:ignore
-
old new 4 4 *.suo 5 5 *.vsp 6 Doxygen 6 7 Google.ProtocolBuffers-0.9.1.dll 7 8 HeuristicLab 3.3.5.1.ReSharper.user 8 9 HeuristicLab 3.3.6.0.ReSharper.user 9 10 HeuristicLab.4.5.resharper.user 11 HeuristicLab.ExtLibs.6.0.ReSharper.user 10 12 HeuristicLab.resharper.user 11 13 ProtoGen.exe … … 16 18 bin 17 19 protoc.exe 18 HeuristicLab.ExtLibs.6.0.ReSharper.user19 Doxygen
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HeuristicLab.Hive.Azure/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r6604 r7215 98 98 this.targetVariable = original.targetVariable; 99 99 this.allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 100 foreach (var dataset in original.cachedPredictions.Keys) {101 this.cachedPredictions.Add(cloner.Clone(dataset), (double[])original.cachedPredictions[dataset].Clone());102 }103 100 if (original.classValues != null) 104 101 this.classValues = (double[])original.classValues.Clone(); … … 162 159 } 163 160 #endregion 164 // cache for predictions, which is cloned but not persisted, must be cleared when the model is changed165 private Dictionary<Dataset, double[]> cachedPredictions = new Dictionary<Dataset, double[]>();166 161 private IEnumerable<double> GetEstimatedValuesHelper(Dataset dataset, IEnumerable<int> rows) { 167 if (!cachedPredictions.ContainsKey(dataset)) { 168 // create an array of cached predictions which is initially filled with NaNs 169 double[] predictions = Enumerable.Repeat(double.NaN, dataset.Rows).ToArray(); 170 CalculatePredictions(dataset, rows, predictions); 171 cachedPredictions.Add(dataset, predictions); 172 } 173 // get the array of predictions and select the subset of requested rows 174 double[] p = cachedPredictions[dataset]; 175 var requestedPredictions = from r in rows 176 select p[r]; 177 // check if the requested predictions contain NaNs 178 // (this means for the request rows some predictions have not been cached) 179 if (requestedPredictions.Any(x => double.IsNaN(x))) { 180 // updated the predictions for currently requested rows 181 CalculatePredictions(dataset, rows, p); 182 cachedPredictions[dataset] = p; 183 // now we can be sure that for the current rows all predictions are available 184 return from r in rows 185 select p[r]; 186 } else { 187 // there were no NaNs => just return the cached predictions 188 return requestedPredictions; 189 } 190 } 191 192 private void CalculatePredictions(Dataset dataset, IEnumerable<int> rows, double[] predictions) { 193 // calculate and cache predictions for the currently requested rows 162 // calculate predictions for the currently requested rows 194 163 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows); 195 164 SVM.Problem scaledProblem = Scaling.Scale(RangeTransform, problem); 196 165 197 // row is the index in the original dataset, 198 // i is the index in the scaled dataset (containing only the necessary rows) 199 int i = 0; 200 foreach (var row in rows) { 201 predictions[row] = SVM.Prediction.Predict(Model, scaledProblem.X[i]); 202 i++; 166 for (int i = 0; i < scaledProblem.Count; i++) { 167 yield return SVM.Prediction.Predict(Model, scaledProblem.X[i]); 203 168 } 204 169 } … … 207 172 public event EventHandler Changed; 208 173 private void OnChanged(EventArgs e) { 209 cachedPredictions.Clear();210 174 var handlers = Changed; 211 175 if (handlers != null) -
branches/HeuristicLab.Hive.Azure/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r6802 r7215 143 143 parameter.Probability = false; 144 144 145 145 146 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows); 146 147 SVM.RangeTransform rangeTransform = SVM.RangeTransform.Compute(problem);
Note: See TracChangeset
for help on using the changeset viewer.