- Timestamp:
- 12/20/11 11:45:18 (13 years ago)
- Location:
- branches/HeuristicLab.TimeSeries
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TimeSeries
-
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r6636 r7213 224 224 } 225 225 } 226 public static new Image StaticItemImage { 227 get { return HeuristicLab.Common.Resources.VSImageLibrary.Event; } 228 } 226 229 public override Image ItemImage { 227 230 get { … … 230 233 else if (ExecutionState == ExecutionState.Paused) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutablePaused; 231 234 else if (ExecutionState == ExecutionState.Stopped) return HeuristicLab.Common.Resources.VSImageLibrary.ExecutableStopped; 232 else return HeuristicLab.Common.Resources.VSImageLibrary.Event;235 else return base.ItemImage; 233 236 } 234 237 } … … 278 281 int testEnd = (i + 1) == Folds.Value ? SamplesEnd.Value : (i + 1) * testSamplesCount + SamplesStart.Value; 279 282 283 problem.ProblemData.TrainingPartition.Start = SamplesStart.Value; 284 problem.ProblemData.TrainingPartition.End = SamplesEnd.Value; 280 285 problem.ProblemData.TestPartition.Start = testStart; 281 286 problem.ProblemData.TestPartition.End = testEnd; … … 515 520 throw new InvalidOperationException("Can not change number of folds if the execution state is not prepared."); 516 521 } 522 523 private bool samplesChanged = false; 517 524 private void SamplesStart_ValueChanged(object sender, EventArgs e) { 525 samplesChanged = true; 518 526 if (Problem != null) Problem.ProblemData.TrainingPartition.Start = SamplesStart.Value; 527 samplesChanged = false; 519 528 } 520 529 private void SamplesEnd_ValueChanged(object sender, EventArgs e) { 530 samplesChanged = true; 521 531 if (Problem != null) Problem.ProblemData.TrainingPartition.End = SamplesEnd.Value; 532 samplesChanged = false; 522 533 } 523 534 … … 543 554 throw new ArgumentException("A cross validation algorithm can only contain DataAnalysisProblems."); 544 555 } 545 algorithm.Problem.Reset += (x, y) => OnProblemChanged();556 algorithm.Problem.Reset += (x, y) => OnProblemChanged(); 546 557 problem = (IDataAnalysisProblem)algorithm.Problem; 547 558 OnProblemChanged(); … … 551 562 EventHandler handler = ProblemChanged; 552 563 if (handler != null) handler(this, EventArgs.Empty); 564 if (samplesChanged) return; 553 565 554 566 SamplesStart.Value = 0; -
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassificationSolution.cs
r6589 r7213 51 51 return new NeuralNetworkClassificationSolution(this, cloner); 52 52 } 53 54 53 protected override void RecalculateResults() { 55 54 CalculateResults(); -
branches/HeuristicLab.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r6604 r7213 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.TimeSeries/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClusteringModel.cs
r5809 r7213 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System. IO;23 using System.Drawing; 25 24 using System.Linq; 26 using System.Text;27 25 using HeuristicLab.Common; 28 26 using HeuristicLab.Core; 29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using SVM;31 28 using HeuristicLab.Problems.DataAnalysis; 32 using System.Drawing;33 29 34 30 namespace HeuristicLab.Algorithms.DataAnalysis { … … 39 35 [Item("KMeansClusteringModel", "Represents a k-Means clustering model.")] 40 36 public sealed class KMeansClusteringModel : NamedItem, IClusteringModel { 41 public override ImageItemImage {37 public static new Image StaticItemImage { 42 38 get { return HeuristicLab.Common.Resources.VSImageLibrary.Function; } 43 39 }
Note: See TracChangeset
for help on using the changeset viewer.