- Timestamp:
- 07/17/11 22:51:11 (14 years ago)
- Location:
- branches/QAPAlgorithms
- Files:
-
- 10 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/QAPAlgorithms
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.3/HeuristicLabAlgorithmsDataAnalysisPlugin.cs.frame
r6099 r6569 26 26 /// Plugin class for HeuristicLab.Algorithms.DataAnalysis plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3. 4.$WCREV$")]28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "3.3.5.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.3.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Collections", "3.3")] -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.3/Properties/AssemblyInfo.frame
r6099 r6569 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.3.0.0")] 55 [assembly: AssemblyFileVersion("3.3. 4.$WCREV$")]55 [assembly: AssemblyFileVersion("3.3.5.$WCREV$")] -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r6250 r6569 34 34 35 35 namespace HeuristicLab.Algorithms.DataAnalysis { 36 [Item("Cross Validation", "Cross Validation wrapper for data analysis algorithms.")]36 [Item("Cross Validation", "Cross-validation wrapper for data analysis algorithms.")] 37 37 [Creatable("Data Analysis")] 38 38 [StorableClass] … … 363 363 364 364 public void CollectResultValues(IDictionary<string, IItem> results) { 365 var clonedResults = (ResultCollection)this.results.Clone(); 366 foreach (var result in clonedResults) { 367 results.Add(result.Name, result.Value); 368 } 369 } 370 371 private void AggregateResultValues(IDictionary<string, IItem> results) { 365 372 Dictionary<string, List<double>> resultValues = new Dictionary<string, List<double>>(); 366 373 IEnumerable<IRun> runs = clonedAlgorithms.Select(alg => alg.Runs.FirstOrDefault()).Where(run => run != null); … … 397 404 List<IResult> aggregatedResults = new List<IResult>(); 398 405 foreach (KeyValuePair<string, List<IRegressionSolution>> solutions in resultSolutions) { 399 var problemDataClone = (IRegressionProblemData)Problem.ProblemData.Clone(); 406 // clone manually to correctly clone references between cloned root objects 407 Cloner cloner = new Cloner(); 408 var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData); 409 // set partitions of problem data clone correctly 400 410 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; 401 411 problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value; 402 var ensembleSolution = new RegressionEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone, 403 solutions.Value.Select(x => x.ProblemData.TrainingPartition), 404 solutions.Value.Select(x => x.ProblemData.TestPartition)); 412 // clone models 413 var ensembleSolution = new RegressionEnsembleSolution( 414 solutions.Value.Select(x => cloner.Clone(x.Model)), 415 problemDataClone, 416 solutions.Value.Select(x => cloner.Clone(x.ProblemData.TrainingPartition)), 417 solutions.Value.Select(x => cloner.Clone(x.ProblemData.TestPartition))); 405 418 406 419 aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution)); … … 425 438 var aggregatedResults = new List<IResult>(); 426 439 foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) { 427 var problemDataClone = (IClassificationProblemData)Problem.ProblemData.Clone(); 440 // clone manually to correctly clone references between cloned root objects 441 Cloner cloner = new Cloner(); 442 var problemDataClone = (IClassificationProblemData)cloner.Clone(Problem.ProblemData); 443 // set partitions of problem data clone correctly 428 444 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; 429 445 problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value; 430 var ensembleSolution = new ClassificationEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone, 431 solutions.Value.Select(x => x.ProblemData.TrainingPartition), 432 solutions.Value.Select(x => x.ProblemData.TestPartition)); 446 // clone models 447 var ensembleSolution = new ClassificationEnsembleSolution( 448 solutions.Value.Select(x => cloner.Clone(x.Model)), 449 problemDataClone, 450 solutions.Value.Select(x => cloner.Clone(x.ProblemData.TrainingPartition)), 451 solutions.Value.Select(x => cloner.Clone(x.ProblemData.TestPartition))); 433 452 434 453 aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution)); … … 553 572 } else 554 573 SamplesEnd.Value = 0; 574 575 SamplesStart_ValueChanged(this, EventArgs.Empty); 576 SamplesEnd_ValueChanged(this, EventArgs.Empty); 555 577 } 556 578 … … 699 721 stopPending = false; 700 722 Dictionary<string, IItem> collectedResults = new Dictionary<string, IItem>(); 701 CollectResultValues(collectedResults);723 AggregateResultValues(collectedResults); 702 724 results.AddRange(collectedResults.Select(x => new Result(x.Key, x.Value)).Cast<IResult>().ToArray()); 703 725 runsCounter++; -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
r5809 r6569 21 21 22 22 using System; 23 using System.Linq; 23 using System.Threading; 24 using System.Threading.Tasks; 24 25 using HeuristicLab.Common; 25 using HeuristicLab.Core;26 using HeuristicLab.Data;27 26 using HeuristicLab.Optimization; 28 using HeuristicLab.Parameters;29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 using HeuristicLab.Problems.DataAnalysis; 31 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;32 using System.Collections.Generic;33 using HeuristicLab.Problems.DataAnalysis.Symbolic;34 using System.Threading.Tasks;35 using System.Threading;36 29 37 30 namespace HeuristicLab.Algorithms.DataAnalysis { … … 57 50 } 58 51 #endregion 59 52 60 53 private DateTime lastUpdateTime; 61 54 … … 103 96 private void Run(object state) { 104 97 CancellationToken cancellationToken = (CancellationToken)state; 105 OnStarted();106 98 lastUpdateTime = DateTime.Now; 107 99 System.Timers.Timer timer = new System.Timers.Timer(250); -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r6241 r6569 129 129 <SubType>Code</SubType> 130 130 </Compile> 131 <Compile Include="Linear\LogitClassificationSolution.cs" /> 132 <Compile Include="Linear\LogitModel.cs" /> 133 <Compile Include="Linear\MultinomialLogitClassification.cs" /> 131 134 <Compile Include="Properties\AssemblyInfo.cs" /> 132 135 <Compile Include="RandomForest\RandomForestClassificationSolution.cs" /> -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLabAlgorithmsDataAnalysisPlugin.cs.frame
r5869 r6569 26 26 /// Plugin class for HeuristicLab.Algorithms.DataAnalysis plugin. 27 27 /// </summary> 28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "Provides wrappers for data analysis algorithms implemented in external libraries (linear regression, linear discriminant analysis, k-means clustering, support vector classification and regression)", "3.4. 0.$WCREV$")]28 [Plugin("HeuristicLab.Algorithms.DataAnalysis", "Provides wrappers for data analysis algorithms implemented in external libraries (linear regression, linear discriminant analysis, k-means clustering, support vector classification and regression)", "3.4.1.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Algorithms.DataAnalysis-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.ALGLIB", "3.1.0")] -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r6240 r6569 111 111 112 112 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter()), problemData); 113 solution.Model.Name = "Linear Regression Model"; 113 114 return solution; 114 115 } -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/Properties/AssemblyInfo.frame
r5869 r6569 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.4.0.0")] 55 [assembly: AssemblyFileVersion("3.4. 0.$WCREV$")]55 [assembly: AssemblyFileVersion("3.4.1.$WCREV$")] -
branches/QAPAlgorithms/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorMachineModel.cs
r5861 r6569 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 } 100 103 if (original.classValues != null) 101 104 this.classValues = (double[])original.classValues.Clone(); … … 145 148 } 146 149 #endregion 150 // cache for predictions, which is cloned but not persisted, must be cleared when the model is changed 151 private Dictionary<Dataset, double[]> cachedPredictions = new Dictionary<Dataset, double[]>(); 147 152 private IEnumerable<double> GetEstimatedValuesHelper(Dataset dataset, IEnumerable<int> rows) { 153 if (!cachedPredictions.ContainsKey(dataset)) { 154 // create an array of cached predictions which is initially filled with NaNs 155 double[] predictions = Enumerable.Repeat(double.NaN, dataset.Rows).ToArray(); 156 CalculatePredictions(dataset, rows, predictions); 157 cachedPredictions.Add(dataset, predictions); 158 } 159 // get the array of predictions and select the subset of requested rows 160 double[] p = cachedPredictions[dataset]; 161 var requestedPredictions = from r in rows 162 select p[r]; 163 // check if the requested predictions contain NaNs 164 // (this means for the request rows some predictions have not been cached) 165 if (requestedPredictions.Any(x => double.IsNaN(x))) { 166 // updated the predictions for currently requested rows 167 CalculatePredictions(dataset, rows, p); 168 cachedPredictions[dataset] = p; 169 // now we can be sure that for the current rows all predictions are available 170 return from r in rows 171 select p[r]; 172 } else { 173 // there were no NaNs => just return the cached predictions 174 return requestedPredictions; 175 } 176 } 177 178 private void CalculatePredictions(Dataset dataset, IEnumerable<int> rows, double[] predictions) { 179 // calculate and cache predictions for the currently requested rows 148 180 SVM.Problem problem = SupportVectorMachineUtil.CreateSvmProblem(dataset, targetVariable, allowedInputVariables, rows); 149 181 SVM.Problem scaledProblem = Scaling.Scale(RangeTransform, problem); 150 182 151 foreach (var row in Enumerable.Range(0, scaledProblem.Count)) { 152 yield return SVM.Prediction.Predict(Model, scaledProblem.X[row]); 153 } 154 } 183 // row is the index in the original dataset, 184 // i is the index in the scaled dataset (containing only the necessary rows) 185 int i = 0; 186 foreach (var row in rows) { 187 predictions[row] = SVM.Prediction.Predict(Model, scaledProblem.X[i]); 188 i++; 189 } 190 } 191 155 192 #region events 156 193 public event EventHandler Changed; 157 194 private void OnChanged(EventArgs e) { 195 cachedPredictions.Clear(); 158 196 var handlers = Changed; 159 197 if (handlers != null)
Note: See TracChangeset
for help on using the changeset viewer.