Changeset 14836
- Timestamp:
- 04/10/17 15:48:20 (8 years ago)
- Location:
- branches/TSNE/HeuristicLab.Algorithms.DataAnalysis
- Files:
-
- 34 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis
- Property svn:mergeinfo changed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneR.cs
r14185 r14836 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using System.Threading; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; … … 58 60 } 59 61 60 protected override void Run( ) {62 protected override void Run(CancellationToken cancellationToken) { 61 63 var solution = CreateOneRSolution(Problem.ProblemData, MinBucketSizeParameter.Value.Value); 62 64 Results.Add(new Result("OneR solution", "The 1R classifier.", solution)); … … 64 66 65 67 public static IClassificationSolution CreateOneRSolution(IClassificationProblemData problemData, int minBucketSize = 6) { 68 var classValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 69 var model1 = FindBestDoubleVariableModel(problemData, minBucketSize); 70 var model2 = FindBestFactorModel(problemData); 71 72 if (model1 == null && model2 == null) throw new InvalidProgramException("Could not create OneR solution"); 73 else if (model1 == null) return new OneFactorClassificationSolution(model2, (IClassificationProblemData)problemData.Clone()); 74 else if (model2 == null) return new OneRClassificationSolution(model1, (IClassificationProblemData)problemData.Clone()); 75 else { 76 var model1EstimatedValues = model1.GetEstimatedClassValues(problemData.Dataset, problemData.TrainingIndices); 77 var model1NumCorrect = classValues.Zip(model1EstimatedValues, (a, b) => a.IsAlmost(b)).Count(e => e); 78 79 var model2EstimatedValues = model2.GetEstimatedClassValues(problemData.Dataset, problemData.TrainingIndices); 80 var model2NumCorrect = classValues.Zip(model2EstimatedValues, (a, b) => a.IsAlmost(b)).Count(e => e); 81 82 if (model1NumCorrect > model2NumCorrect) { 83 return new OneRClassificationSolution(model1, (IClassificationProblemData)problemData.Clone()); 84 } else { 85 return new OneFactorClassificationSolution(model2, (IClassificationProblemData)problemData.Clone()); 86 } 87 } 88 } 89 90 private static OneRClassificationModel FindBestDoubleVariableModel(IClassificationProblemData problemData, int minBucketSize = 6) { 66 91 var bestClassified = 0; 67 92 List<Split> bestSplits = null; … … 70 95 var classValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 71 96 72 foreach (var variable in problemData.AllowedInputVariables) { 97 var allowedInputVariables = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<double>); 98 99 if (!allowedInputVariables.Any()) return null; 100 101 foreach (var variable in allowedInputVariables) { 73 102 var inputValues = problemData.Dataset.GetDoubleValues(variable, problemData.TrainingIndices); 74 103 var samples = inputValues.Zip(classValues, (i, v) => new Sample(i, v)).OrderBy(s => s.inputValue); 75 104 76 var missingValuesDistribution = samples.Where(s => double.IsNaN(s.inputValue)).GroupBy(s => s.classValue).ToDictionary(s => s.Key, s => s.Count()).MaxItems(s => s.Value).FirstOrDefault(); 105 var missingValuesDistribution = samples 106 .Where(s => double.IsNaN(s.inputValue)).GroupBy(s => s.classValue) 107 .ToDictionary(s => s.Key, s => s.Count()) 108 .MaxItems(s => s.Value) 109 .FirstOrDefault(); 77 110 78 111 //calculate class distributions for all distinct inputValues … … 119 152 while (sample.inputValue >= splits[splitIndex].thresholdValue) 120 153 splitIndex++; 121 correctClassified += sample.classValue == splits[splitIndex].classValue? 1 : 0;154 correctClassified += sample.classValue.IsAlmost(splits[splitIndex].classValue) ? 1 : 0; 122 155 } 123 156 correctClassified += missingValuesDistribution.Value; … … 133 166 //remove neighboring splits with the same class value 134 167 for (int i = 0; i < bestSplits.Count - 1; i++) { 135 if (bestSplits[i].classValue == bestSplits[i + 1].classValue) {168 if (bestSplits[i].classValue.IsAlmost(bestSplits[i + 1].classValue)) { 136 169 bestSplits.Remove(bestSplits[i]); 137 170 i--; … … 139 172 } 140 173 141 var model = new OneRClassificationModel(problemData.TargetVariable, bestVariable, bestSplits.Select(s => s.thresholdValue).ToArray(), bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass); 142 var solution = new OneRClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 143 144 return solution; 174 var model = new OneRClassificationModel(problemData.TargetVariable, bestVariable, 175 bestSplits.Select(s => s.thresholdValue).ToArray(), 176 bestSplits.Select(s => s.classValue).ToArray(), bestMissingValuesClass); 177 178 return model; 179 } 180 private static OneFactorClassificationModel FindBestFactorModel(IClassificationProblemData problemData) { 181 var classValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices); 182 var defaultClass = FindMostFrequentClassValue(classValues); 183 // only select string variables 184 var allowedInputVariables = problemData.AllowedInputVariables.Where(problemData.Dataset.VariableHasType<string>); 185 186 if (!allowedInputVariables.Any()) return null; 187 188 OneFactorClassificationModel bestModel = null; 189 var bestModelNumCorrect = 0; 190 191 foreach (var variable in allowedInputVariables) { 192 var variableValues = problemData.Dataset.GetStringValues(variable, problemData.TrainingIndices); 193 var groupedClassValues = variableValues 194 .Zip(classValues, (v, c) => new KeyValuePair<string, double>(v, c)) 195 .GroupBy(kvp => kvp.Key) 196 .ToDictionary(g => g.Key, g => FindMostFrequentClassValue(g.Select(kvp => kvp.Value))); 197 198 var model = new OneFactorClassificationModel(problemData.TargetVariable, variable, 199 groupedClassValues.Select(kvp => kvp.Key).ToArray(), groupedClassValues.Select(kvp => kvp.Value).ToArray(), defaultClass); 200 201 var modelEstimatedValues = model.GetEstimatedClassValues(problemData.Dataset, problemData.TrainingIndices); 202 var modelNumCorrect = classValues.Zip(modelEstimatedValues, (a, b) => a.IsAlmost(b)).Count(e => e); 203 if (modelNumCorrect > bestModelNumCorrect) { 204 bestModelNumCorrect = modelNumCorrect; 205 bestModel = model; 206 } 207 } 208 209 return bestModel; 210 } 211 212 private static double FindMostFrequentClassValue(IEnumerable<double> classValues) { 213 return classValues.GroupBy(c => c).OrderByDescending(g => g.Count()).Select(g => g.Key).First(); 145 214 } 146 215 -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationModel.cs
r14185 r14836 31 31 [StorableClass] 32 32 [Item("OneR Classification Model", "A model that uses intervals for one variable to determine the class.")] 33 public class OneRClassificationModel : ClassificationModel {33 public sealed class OneRClassificationModel : ClassificationModel { 34 34 public override IEnumerable<string> VariablesUsedForPrediction { 35 35 get { return new[] { Variable }; } … … 37 37 38 38 [Storable] 39 pr otectedstring variable;39 private string variable; 40 40 public string Variable { 41 41 get { return variable; } … … 43 43 44 44 [Storable] 45 pr otecteddouble[] splits;45 private double[] splits; 46 46 public double[] Splits { 47 47 get { return splits; } … … 49 49 50 50 [Storable] 51 pr otecteddouble[] classes;51 private double[] classes; 52 52 public double[] Classes { 53 53 get { return classes; } … … 55 55 56 56 [Storable] 57 pr otecteddouble missingValuesClass;57 private double missingValuesClass; 58 58 public double MissingValuesClass { 59 59 get { return missingValuesClass; } … … 61 61 62 62 [StorableConstructor] 63 pr otectedOneRClassificationModel(bool deserializing) : base(deserializing) { }64 pr otectedOneRClassificationModel(OneRClassificationModel original, Cloner cloner)63 private OneRClassificationModel(bool deserializing) : base(deserializing) { } 64 private OneRClassificationModel(OneRClassificationModel original, Cloner cloner) 65 65 : base(original, cloner) { 66 66 this.variable = (string)original.variable; 67 67 this.splits = (double[])original.splits.Clone(); 68 68 this.classes = (double[])original.classes.Clone(); 69 this.missingValuesClass = original.missingValuesClass; 69 70 } 70 71 public override IDeepCloneable Clone(Cloner cloner) { return new OneRClassificationModel(this, cloner); } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/OneRClassificationSolution.cs
r14185 r14836 28 28 [StorableClass] 29 29 [Item(Name = "OneR Classification Solution", Description = "Represents a OneR classification solution which uses only a single feature with potentially multiple thresholds for class prediction.")] 30 public class OneRClassificationSolution : ClassificationSolution {30 public sealed class OneRClassificationSolution : ClassificationSolution { 31 31 public new OneRClassificationModel Model { 32 32 get { return (OneRClassificationModel)base.Model; } … … 35 35 36 36 [StorableConstructor] 37 pr otectedOneRClassificationSolution(bool deserializing) : base(deserializing) { }38 pr otectedOneRClassificationSolution(OneRClassificationSolution original, Cloner cloner) : base(original, cloner) { }37 private OneRClassificationSolution(bool deserializing) : base(deserializing) { } 38 private OneRClassificationSolution(OneRClassificationSolution original, Cloner cloner) : base(original, cloner) { } 39 39 public OneRClassificationSolution(OneRClassificationModel model, IClassificationProblemData problemData) 40 40 : base(model, problemData) { -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/BaselineClassifiers/ZeroR.cs
r14185 r14836 21 21 22 22 using System.Linq; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 49 50 } 50 51 51 protected override void Run( ) {52 protected override void Run(CancellationToken cancellationToken) { 52 53 var solution = CreateZeroRSolution(Problem.ProblemData); 53 54 Results.Add(new Result("ZeroR solution", "The simplest possible classifier, ZeroR always predicts the majority class.", solution)); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs
r14185 r14836 451 451 var aggregatedResults = new List<IResult>(); 452 452 foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) { 453 // clone manually to correctly clone references between cloned root objects 454 Cloner cloner = new Cloner(); 455 var problemDataClone = (IClassificationProblemData)cloner.Clone(Problem.ProblemData); 453 // at least one algorithm (GBT with logistic regression loss) produces a classification solution even though the original problem is a regression problem. 454 var targetVariable = solutions.Value.First().ProblemData.TargetVariable; 455 var problemDataClone = new ClassificationProblemData(Problem.ProblemData.Dataset, 456 Problem.ProblemData.AllowedInputVariables, targetVariable); 456 457 // set partitions of problem data clone correctly 457 458 problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value; -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/FixedDataAnalysisAlgorithm.cs
r14185 r14836 21 21 22 22 using System; 23 using System.Threading;24 using System.Threading.Tasks;25 23 using HeuristicLab.Common; 26 24 using HeuristicLab.Optimization; … … 30 28 namespace HeuristicLab.Algorithms.DataAnalysis { 31 29 [StorableClass] 32 public abstract class FixedDataAnalysisAlgorithm<T> : Algorithm, 33 IDataAnalysisAlgorithm<T>, 34 IStorableContent 35 where T : class, IDataAnalysisProblem { 36 public string Filename { get; set; } 37 30 public abstract class FixedDataAnalysisAlgorithm<T> : BasicAlgorithm where T : class, IDataAnalysisProblem { 38 31 #region Properties 39 32 public override Type ProblemType { … … 44 37 set { base.Problem = value; } 45 38 } 46 [Storable]47 private ResultCollection results;48 public override ResultCollection Results {49 get { return results; }50 }51 39 #endregion 52 40 53 p rivate DateTime lastUpdateTime;41 public override bool SupportsPause { get { return false; } } 54 42 55 43 [StorableConstructor] 56 44 protected FixedDataAnalysisAlgorithm(bool deserializing) : base(deserializing) { } 57 protected FixedDataAnalysisAlgorithm(FixedDataAnalysisAlgorithm<T> original, Cloner cloner) 58 : base(original, cloner) { 59 results = cloner.Clone(original.Results); 60 } 61 public FixedDataAnalysisAlgorithm() 62 : base() { 63 results = new ResultCollection(); 64 } 65 66 public override void Prepare() { 67 if (Problem != null) base.Prepare(); 68 results.Clear(); 69 OnPrepared(); 70 } 71 72 public override void Start() { 73 base.Start(); 74 var cancellationTokenSource = new CancellationTokenSource(); 75 76 OnStarted(); 77 Task task = Task.Factory.StartNew(Run, cancellationTokenSource.Token, cancellationTokenSource.Token); 78 task.ContinueWith(t => { 79 try { 80 t.Wait(); 81 } 82 catch (AggregateException ex) { 83 try { 84 ex.Flatten().Handle(x => x is OperationCanceledException); 85 } 86 catch (AggregateException remaining) { 87 if (remaining.InnerExceptions.Count == 1) OnExceptionOccurred(remaining.InnerExceptions[0]); 88 else OnExceptionOccurred(remaining); 89 } 90 } 91 cancellationTokenSource.Dispose(); 92 cancellationTokenSource = null; 93 OnStopped(); 94 }); 95 } 96 private void Run(object state) { 97 CancellationToken cancellationToken = (CancellationToken)state; 98 lastUpdateTime = DateTime.UtcNow; 99 System.Timers.Timer timer = new System.Timers.Timer(250); 100 timer.AutoReset = true; 101 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 102 timer.Start(); 103 try { 104 Run(); 105 } 106 finally { 107 timer.Elapsed -= new System.Timers.ElapsedEventHandler(timer_Elapsed); 108 timer.Stop(); 109 ExecutionTime += DateTime.UtcNow - lastUpdateTime; 110 } 111 112 cancellationToken.ThrowIfCancellationRequested(); 113 } 114 protected abstract void Run(); 115 #region Events 116 protected override void OnProblemChanged() { 117 Problem.Reset += new EventHandler(Problem_Reset); 118 base.OnProblemChanged(); 119 } 120 private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { 121 System.Timers.Timer timer = (System.Timers.Timer)sender; 122 timer.Enabled = false; 123 DateTime now = DateTime.UtcNow; 124 ExecutionTime += now - lastUpdateTime; 125 lastUpdateTime = now; 126 timer.Enabled = true; 127 } 128 #endregion 45 protected FixedDataAnalysisAlgorithm(FixedDataAnalysisAlgorithm<T> original, Cloner cloner) : base(original, cloner) { } 46 public FixedDataAnalysisAlgorithm() : base() { } 129 47 130 48 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GBM/GradientBoostingRegressionAlgorithm.cs
r14558 r14836 44 44 [StorableClass] 45 45 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 350)] 46 public class GradientBoostingRegressionAlgorithm : BasicAlgorithm, IDataAnalysisAlgorithm<IRegressionProblem> { 47 public override Type ProblemType { 48 get { return typeof(IRegressionProblem); } 49 } 50 51 public new IRegressionProblem Problem { 52 get { return (IRegressionProblem)base.Problem; } 53 set { base.Problem = value; } 54 } 55 public override bool SupportsPause 56 { 57 get { return false; } 58 } 46 public class GradientBoostingRegressionAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 59 47 60 48 #region ParameterNames -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessBase.cs
r14185 r14836 21 21 #endregion 22 22 23 using System.Linq; 23 24 using HeuristicLab.Algorithms.GradientDescent; 24 25 using HeuristicLab.Common; … … 119 120 120 121 // necessary for BFGS 121 Parameters.Add(new ValueParameter<BoolValue>("Maximization", new BoolValue(false)));122 Parameters["Maximization "].Hidden = true;122 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization (BFGS)", new BoolValue(false))); 123 Parameters["Maximization (BFGS)"].Hidden = true; 123 124 124 125 var randomCreator = new HeuristicLab.Random.RandomCreator(); … … 164 165 modelCreator.Successor = updateResults; 165 166 167 updateResults.MaximizationParameter.ActualName = "Maximization (BFGS)"; 166 168 updateResults.StateParameter.ActualName = bfgsInitializer.StateParameter.Name; 167 169 updateResults.QualityParameter.ActualName = NegativeLogLikelihoodParameterName; … … 197 199 // BackwardsCompatibility3.4 198 200 #region Backwards compatible code, remove with 3.5 199 if (!Parameters.ContainsKey("Maximization")) { 200 Parameters.Add(new ValueParameter<BoolValue>("Maximization", new BoolValue(false))); 201 Parameters["Maximization"].Hidden = true; 201 if (Parameters.ContainsKey("Maximization")) { 202 Parameters.Remove("Maximization"); 203 } 204 205 if (!Parameters.ContainsKey("Maximization (BFGS)")) { 206 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization (BFGS)", new BoolValue(false))); 207 Parameters["Maximization (BFGS)"].Hidden = true; 208 OperatorGraph.Operators.OfType<LbfgsUpdateResults>().First().MaximizationParameter.ActualName = "Maximization BFGS"; 202 209 } 203 210 -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GaussianProcess/GaussianProcessClassificationModelCreator.cs
r14185 r14836 67 67 HyperparameterGradientsParameter.ActualValue = new RealVector(model.HyperparameterGradients); 68 68 return base.Apply(); 69 } catch (ArgumentException) { } catch (alglib.alglibexception) { } 69 } catch (ArgumentException) { 70 } catch (alglib.alglibexception) { 71 } 70 72 NegativeLogLikelihoodParameter.ActualValue = new DoubleValue(1E300); 71 73 HyperparameterGradientsParameter.ActualValue = new RealVector(Hyperparameter.Count()); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithm.cs
r14558 r14836 38 38 [StorableClass] 39 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 125)] 40 public class GradientBoostedTreesAlgorithm : BasicAlgorithm, IDataAnalysisAlgorithm<IRegressionProblem> { 41 public override Type ProblemType 42 { 43 get { return typeof(IRegressionProblem); } 44 } 45 public new IRegressionProblem Problem 46 { 47 get { return (IRegressionProblem)base.Problem; } 48 set { base.Problem = value; } 49 } 50 public override bool SupportsPause 51 { 52 get { return false; } 53 } 54 40 public class GradientBoostedTreesAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 55 41 #region ParameterNames 56 42 private const string IterationsParameterName = "Iterations"; … … 289 275 var classificationProblemData = new ClassificationProblemData(problemData.Dataset, 290 276 problemData.AllowedInputVariables, problemData.TargetVariable, problemData.Transformations); 291 classificationModel.RecalculateModelParameters(classificationProblemData, classificationProblemData.TrainingIndices); 277 classificationProblemData.TrainingPartition.Start = Problem.ProblemData.TrainingPartition.Start; 278 classificationProblemData.TrainingPartition.End = Problem.ProblemData.TrainingPartition.End; 279 classificationProblemData.TestPartition.Start = Problem.ProblemData.TestPartition.Start; 280 classificationProblemData.TestPartition.End = Problem.ProblemData.TestPartition.End; 281 282 classificationModel.SetThresholdsAndClassValues(new double[] { double.NegativeInfinity, 0.0 }, new []{ 0.0, 1.0 }); 283 292 284 293 285 var classificationSolution = new DiscriminantFunctionClassificationSolution(classificationModel, classificationProblemData); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/GradientBoostedTrees/GradientBoostedTreesAlgorithmStatic.cs
r14185 r14836 148 148 // for custom stepping & termination 149 149 public static IGbmState CreateGbmState(IRegressionProblemData problemData, ILossFunction lossFunction, uint randSeed, int maxSize = 3, double r = 0.66, double m = 0.5, double nu = 0.01) { 150 // check input variables. Only double variables are allowed. 151 var invalidInputs = 152 problemData.AllowedInputVariables.Where(name => !problemData.Dataset.VariableHasType<double>(name)); 153 if (invalidInputs.Any()) 154 throw new NotSupportedException("Gradient tree boosting only supports real-valued variables. Unsupported inputs: " + string.Join(", ", invalidInputs)); 155 150 156 return new GbmState(problemData, lossFunction, randSeed, maxSize, r, m, nu); 151 157 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/HeuristicLab.Algorithms.DataAnalysis-3.4.csproj
r14787 r14836 215 215 </ItemGroup> 216 216 <ItemGroup> 217 <Compile Include="BaselineClassifiers\OneFactorClassificationModel.cs" /> 218 <Compile Include="BaselineClassifiers\OneFactorClassificationSolution.cs" /> 217 219 <Compile Include="BaselineClassifiers\OneR.cs" /> 218 220 <Compile Include="BaselineClassifiers\OneRClassificationModel.cs" /> -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/AlglibUtil.cs
r14185 r14836 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; … … 27 28 public static class AlglibUtil { 28 29 public static double[,] PrepareInputMatrix(IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows) { 29 List<string> variablesList = variables.ToList(); 30 // check input variables. Only double variables are allowed. 31 var invalidInputs = 32 variables.Where(name => !dataset.VariableHasType<double>(name)); 33 if (invalidInputs.Any()) 34 throw new NotSupportedException("Unsupported inputs: " + string.Join(", ", invalidInputs)); 35 30 36 List<int> rowsList = rows.ToList(); 31 32 double[,] matrix = new double[rowsList.Count, variablesList.Count]; 37 double[,] matrix = new double[rowsList.Count, variables.Count()]; 33 38 34 39 int col = 0; … … 45 50 return matrix; 46 51 } 52 47 53 public static double[,] PrepareAndScaleInputMatrix(IDataset dataset, IEnumerable<string> variables, IEnumerable<int> rows, Scaling scaling) { 54 // check input variables. Only double variables are allowed. 55 var invalidInputs = 56 variables.Where(name => !dataset.VariableHasType<double>(name)); 57 if (invalidInputs.Any()) 58 throw new NotSupportedException("Unsupported inputs: " + string.Join(", ", invalidInputs)); 59 48 60 List<string> variablesList = variables.ToList(); 49 61 List<int> rowsList = rows.ToList(); … … 64 76 return matrix; 65 77 } 78 79 /// <summary> 80 /// Prepares a binary data matrix from a number of factors and specified factor values 81 /// </summary> 82 /// <param name="dataset">A dataset that contains the variable values</param> 83 /// <param name="factorVariables">An enumerable of categorical variables (factors). For each variable an enumerable of values must be specified.</param> 84 /// <param name="rows">An enumerable of row indices for the dataset</param> 85 /// <returns></returns> 86 /// <remarks>Factor variables (categorical variables) are split up into multiple binary variables one for each specified value.</remarks> 87 public static double[,] PrepareInputMatrix( 88 IDataset dataset, 89 IEnumerable<KeyValuePair<string, IEnumerable<string>>> factorVariables, 90 IEnumerable<int> rows) { 91 // check input variables. Only string variables are allowed. 92 var invalidInputs = 93 factorVariables.Select(kvp => kvp.Key).Where(name => !dataset.VariableHasType<string>(name)); 94 if (invalidInputs.Any()) 95 throw new NotSupportedException("Unsupported inputs: " + string.Join(", ", invalidInputs)); 96 97 int numBinaryColumns = factorVariables.Sum(kvp => kvp.Value.Count()); 98 99 List<int> rowsList = rows.ToList(); 100 double[,] matrix = new double[rowsList.Count, numBinaryColumns]; 101 102 int col = 0; 103 foreach (var kvp in factorVariables) { 104 var varName = kvp.Key; 105 var cats = kvp.Value; 106 if (!cats.Any()) continue; 107 foreach (var cat in cats) { 108 var values = dataset.GetStringValues(varName, rows); 109 int row = 0; 110 foreach (var value in values) { 111 matrix[row, col] = value == cat ? 1 : 0; 112 row++; 113 } 114 col++; 115 } 116 } 117 return matrix; 118 } 119 120 public static IEnumerable<KeyValuePair<string, IEnumerable<string>>> GetFactorVariableValues(IDataset ds, IEnumerable<string> factorVariables, IEnumerable<int> rows) { 121 return from factor in factorVariables 122 let distinctValues = ds.GetStringValues(factor, rows).Distinct().ToArray() 123 // 1 distinct value => skip (constant) 124 // 2 distinct values => only take one of the two values 125 // >=3 distinct values => create a binary value for each value 126 let reducedValues = distinctValues.Length <= 2 127 ? distinctValues.Take(distinctValues.Length - 1) 128 : distinctValues 129 select new KeyValuePair<string, IEnumerable<string>>(factor, reducedValues); 130 } 66 131 } 67 132 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearDiscriminantAnalysis.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 36 37 /// Linear discriminant analysis classification algorithm. 37 38 /// </summary> 38 [Item("Linear Discriminant Analysis ", "Linear discriminant analysis classification algorithm (wrapper for ALGLIB).")]39 [Item("Linear Discriminant Analysis (LDA)", "Linear discriminant analysis classification algorithm (wrapper for ALGLIB).")] 39 40 [Creatable(CreatableAttribute.Categories.DataAnalysisClassification, Priority = 100)] 40 41 [StorableClass] … … 59 60 60 61 #region Fisher LDA 61 protected override void Run( ) {62 protected override void Run(CancellationToken cancellationToken) { 62 63 var solution = CreateLinearDiscriminantAnalysisSolution(Problem.ProblemData); 63 64 Results.Add(new Result(LinearDiscriminantAnalysisSolutionResultName, "The linear discriminant analysis.", solution)); … … 70 71 IEnumerable<int> rows = problemData.TrainingIndices; 71 72 int nClasses = problemData.ClassNames.Count(); 72 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 73 var doubleVariableNames = allowedInputVariables.Where(dataset.VariableHasType<double>).ToArray(); 74 var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>).ToArray(); 75 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariableNames.Concat(new string[] { targetVariable }), rows); 76 77 var factorVariables = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows); 78 double[,] factorMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows); 79 80 inputMatrix = factorMatrix.HorzCat(inputMatrix); 81 73 82 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 74 83 throw new NotSupportedException("Linear discriminant analysis does not support NaN or infinity values in the input dataset."); … … 82 91 int info; 83 92 double[] w; 84 alglib.fisherlda(inputMatrix, inputMatrix.GetLength(0), allowedInputVariables.Count(), nClasses, out info, out w);93 alglib.fisherlda(inputMatrix, inputMatrix.GetLength(0), inputMatrix.GetLength(1) - 1, nClasses, out info, out w); 85 94 if (info < 1) throw new ArgumentException("Error in calculation of linear discriminant analysis solution"); 86 95 … … 92 101 93 102 int col = 0; 94 foreach (string column in allowedInputVariables) { 103 foreach (var kvp in factorVariables) { 104 var varName = kvp.Key; 105 foreach (var cat in kvp.Value) { 106 BinaryFactorVariableTreeNode vNode = 107 (BinaryFactorVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable().CreateTreeNode(); 108 vNode.VariableName = varName; 109 vNode.VariableValue = cat; 110 vNode.Weight = w[col]; 111 addition.AddSubtree(vNode); 112 col++; 113 } 114 } 115 foreach (string column in doubleVariableNames) { 95 116 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 96 117 vNode.VariableName = column; … … 100 121 } 101 122 102 var model = LinearDiscriminantAnalysis.CreateDiscriminantFunctionModel(tree, new SymbolicDataAnalysisExpressionTreeInterpreter(), problemData, rows);123 var model = CreateDiscriminantFunctionModel(tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter(), problemData, rows); 103 124 SymbolicDiscriminantFunctionClassificationSolution solution = new SymbolicDiscriminantFunctionClassificationSolution(model, (IClassificationProblemData)problemData.Clone()); 104 125 -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/LinearRegression.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 60 61 61 62 #region linear regression 62 protected override void Run( ) {63 protected override void Run(CancellationToken cancellationToken) { 63 64 double rmsError, cvRmsError; 64 65 var solution = CreateLinearRegressionSolution(Problem.ProblemData, out rmsError, out cvRmsError); … … 73 74 IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables; 74 75 IEnumerable<int> rows = problemData.TrainingIndices; 75 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 76 var doubleVariables = allowedInputVariables.Where(dataset.VariableHasType<double>); 77 var factorVariableNames = allowedInputVariables.Where(dataset.VariableHasType<string>); 78 var factorVariables = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows); 79 double[,] binaryMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows); 80 double[,] doubleVarMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariables.Concat(new string[] { targetVariable }), rows); 81 var inputMatrix = binaryMatrix.HorzCat(doubleVarMatrix); 82 76 83 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 77 84 throw new NotSupportedException("Linear regression does not support NaN or infinity values in the input dataset."); … … 98 105 99 106 int col = 0; 100 foreach (string column in allowedInputVariables) { 107 foreach (var kvp in factorVariables) { 108 var varName = kvp.Key; 109 foreach (var cat in kvp.Value) { 110 BinaryFactorVariableTreeNode vNode = 111 (BinaryFactorVariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.BinaryFactorVariable().CreateTreeNode(); 112 vNode.VariableName = varName; 113 vNode.VariableValue = cat; 114 vNode.Weight = coefficients[col]; 115 addition.AddSubtree(vNode); 116 col++; 117 } 118 } 119 foreach (string column in doubleVariables) { 101 120 VariableTreeNode vNode = (VariableTreeNode)new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable().CreateTreeNode(); 102 121 vNode.VariableName = column; … … 110 129 addition.AddSubtree(cNode); 111 130 112 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTree Interpreter()), (IRegressionProblemData)problemData.Clone());131 SymbolicRegressionSolution solution = new SymbolicRegressionSolution(new SymbolicRegressionModel(problemData.TargetVariable, tree, new SymbolicDataAnalysisExpressionTreeLinearInterpreter()), (IRegressionProblemData)problemData.Clone()); 113 132 solution.Model.Name = "Linear Regression Model"; 114 133 solution.Name = "Linear Regression Solution"; -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassification.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 57 58 58 59 #region logit classification 59 protected override void Run( ) {60 protected override void Run(CancellationToken cancellationToken) { 60 61 double rmsError, relClassError; 61 62 var solution = CreateLogitClassificationSolution(Problem.ProblemData, out rmsError, out relClassError); … … 68 69 var dataset = problemData.Dataset; 69 70 string targetVariable = problemData.TargetVariable; 70 IEnumerable<string> allowedInputVariables = problemData.AllowedInputVariables; 71 var doubleVariableNames = problemData.AllowedInputVariables.Where(dataset.VariableHasType<double>); 72 var factorVariableNames = problemData.AllowedInputVariables.Where(dataset.VariableHasType<string>); 71 73 IEnumerable<int> rows = problemData.TrainingIndices; 72 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables.Concat(new string[] { targetVariable }), rows); 74 double[,] inputMatrix = AlglibUtil.PrepareInputMatrix(dataset, doubleVariableNames.Concat(new string[] { targetVariable }), rows); 75 76 var factorVariableValues = AlglibUtil.GetFactorVariableValues(dataset, factorVariableNames, rows); 77 var factorMatrix = AlglibUtil.PrepareInputMatrix(dataset, factorVariableValues, rows); 78 inputMatrix = factorMatrix.HorzCat(inputMatrix); 79 73 80 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 74 81 throw new NotSupportedException("Multinomial logit classification does not support NaN or infinity values in the input dataset."); … … 95 102 relClassError = alglib.mnlrelclserror(lm, inputMatrix, nRows); 96 103 97 MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution(new MultinomialLogitModel(lm, targetVariable, allowedInputVariables, classValues), (IClassificationProblemData)problemData.Clone());104 MultinomialLogitClassificationSolution solution = new MultinomialLogitClassificationSolution(new MultinomialLogitModel(lm, targetVariable, doubleVariableNames, factorVariableValues, classValues), (IClassificationProblemData)problemData.Clone()); 98 105 return solution; 99 106 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitClassificationSolution.cs
r14185 r14836 43 43 : base(original, cloner) { 44 44 } 45 public MultinomialLogitClassificationSolution( MultinomialLogitModel logitModel,IClassificationProblemData problemData)45 public MultinomialLogitClassificationSolution(MultinomialLogitModel logitModel, IClassificationProblemData problemData) 46 46 : base(logitModel, problemData) { 47 47 } -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/Linear/MultinomialLogitModel.cs
r14185 r14836 56 56 [Storable] 57 57 private double[] classValues; 58 [Storable] 59 private List<KeyValuePair<string, IEnumerable<string>>> factorVariables; 60 58 61 [StorableConstructor] 59 62 private MultinomialLogitModel(bool deserializing) … … 68 71 allowedInputVariables = (string[])original.allowedInputVariables.Clone(); 69 72 classValues = (double[])original.classValues.Clone(); 73 this.factorVariables = original.factorVariables.Select(kvp => new KeyValuePair<string, IEnumerable<string>>(kvp.Key, new List<string>(kvp.Value))).ToList(); 70 74 } 71 public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> allowedInputVariables, double[] classValues)75 public MultinomialLogitModel(alglib.logitmodel logitModel, string targetVariable, IEnumerable<string> doubleInputVariables, IEnumerable<KeyValuePair<string, IEnumerable<string>>> factorVariables, double[] classValues) 72 76 : base(targetVariable) { 73 77 this.name = ItemName; 74 78 this.description = ItemDescription; 75 79 this.logitModel = logitModel; 76 this.allowedInputVariables = allowedInputVariables.ToArray(); 80 this.allowedInputVariables = doubleInputVariables.ToArray(); 81 this.factorVariables = factorVariables.Select(kvp => new KeyValuePair<string, IEnumerable<string>>(kvp.Key, new List<string>(kvp.Value))).ToList(); 77 82 this.classValues = (double[])classValues.Clone(); 83 } 84 85 [StorableHook(HookType.AfterDeserialization)] 86 private void AfterDeserialization() { 87 // BackwardsCompatibility3.3 88 #region Backwards compatible code, remove with 3.4 89 factorVariables = new List<KeyValuePair<string, IEnumerable<string>>>(); 90 #endregion 78 91 } 79 92 … … 83 96 84 97 public override IEnumerable<double> GetEstimatedClassValues(IDataset dataset, IEnumerable<int> rows) { 98 85 99 double[,] inputData = AlglibUtil.PrepareInputMatrix(dataset, allowedInputVariables, rows); 100 double[,] factorData = AlglibUtil.PrepareInputMatrix(dataset, factorVariables, rows); 101 102 inputData = factorData.HorzCat(inputData); 86 103 87 104 int n = inputData.GetLength(0); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/MctsSymbolicRegression/MctsSymbolicRegressionAlgorithm.cs
r14558 r14836 37 37 [StorableClass] 38 38 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 250)] 39 public class MctsSymbolicRegressionAlgorithm : BasicAlgorithm { 40 public override Type ProblemType 41 { 42 get { return typeof(IRegressionProblem); } 43 } 44 public new IRegressionProblem Problem 45 { 46 get { return (IRegressionProblem)base.Problem; } 47 set { base.Problem = value; } 48 } 39 public class MctsSymbolicRegressionAlgorithm : FixedDataAnalysisAlgorithm<IRegressionProblem> { 49 40 public override bool SupportsPause 50 41 { -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourClassification.cs
r14235 r14836 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 91 92 92 93 #region nearest neighbour 93 protected override void Run( ) {94 protected override void Run(CancellationToken cancellationToken) { 94 95 double[] weights = null; 95 96 if (Weights != null) weights = Weights.CloneAsArray(); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourModel.cs
r14322 r14836 144 144 if (inputMatrix.Cast<double>().Any(x => double.IsNaN(x) || double.IsInfinity(x))) 145 145 throw new NotSupportedException( 146 "Nearest neighbour classificationdoes not support NaN or infinity values in the input dataset.");146 "Nearest neighbour model does not support NaN or infinity values in the input dataset."); 147 147 148 148 this.kdTree = new alglib.nearestneighbor.kdtree(); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NearestNeighbour/NearestNeighbourRegression.cs
r14235 r14836 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 92 93 93 94 #region nearest neighbour 94 protected override void Run( ) {95 protected override void Run(CancellationToken cancellationToken) { 95 96 double[] weights = null; 96 97 if (Weights != null) weights = Weights.CloneAsArray(); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkClassification.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 168 169 169 170 #region neural network 170 protected override void Run( ) {171 protected override void Run(CancellationToken cancellationToken) { 171 172 double rmsError, avgRelError, relClassError; 172 173 var solution = CreateNeuralNetworkClassificationSolution(Problem.ProblemData, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError, out relClassError); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleClassification.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 154 155 155 156 #region neural network ensemble 156 protected override void Run( ) {157 protected override void Run(CancellationToken cancellationToken) { 157 158 double rmsError, avgRelError, relClassError; 158 159 var solution = CreateNeuralNetworkEnsembleClassificationSolution(Problem.ProblemData, EnsembleSize, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError, out relClassError); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkEnsembleRegression.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 154 155 155 156 #region neural network ensemble 156 protected override void Run( ) {157 protected override void Run(CancellationToken cancellationToken) { 157 158 double rmsError, avgRelError; 158 159 var solution = CreateNeuralNetworkEnsembleRegressionSolution(Problem.ProblemData, EnsembleSize, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NeuralNetwork/NeuralNetworkRegression.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 170 171 171 172 #region neural network 172 protected override void Run( ) {173 protected override void Run(CancellationToken cancellationToken) { 173 174 double rmsError, avgRelError; 174 175 var solution = CreateNeuralNetworkRegressionSolution(Problem.ProblemData, HiddenLayers, NodesInFirstHiddenLayer, NodesInSecondHiddenLayer, Decay, Restarts, out rmsError, out avgRelError); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/NonlinearRegression/NonlinearRegression.cs
r14319 r14836 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using System.Threading; 24 26 using HeuristicLab.Analysis; 25 27 using HeuristicLab.Common; … … 157 159 158 160 #region nonlinear regression 159 protected override void Run( ) {161 protected override void Run(CancellationToken cancellationToken) { 160 162 IRegressionSolution bestSolution = null; 161 163 if (InitializeParametersRandomly) { … … 207 209 var parser = new InfixExpressionParser(); 208 210 var tree = parser.Parse(modelStructure); 211 // parser handles double and string variables equally by creating a VariableTreeNode 212 // post-process to replace VariableTreeNodes by FactorVariableTreeNodes for all string variables 213 var factorSymbol = new FactorVariable(); 214 factorSymbol.VariableNames = 215 problemData.AllowedInputVariables.Where(name => problemData.Dataset.VariableHasType<string>(name)); 216 factorSymbol.AllVariableNames = factorSymbol.VariableNames; 217 factorSymbol.VariableValues = 218 factorSymbol.VariableNames.Select(name => 219 new KeyValuePair<string, Dictionary<string, int>>(name, 220 problemData.Dataset.GetReadOnlyStringValues(name).Distinct() 221 .Select((n, i) => Tuple.Create(n, i)) 222 .ToDictionary(tup => tup.Item1, tup => tup.Item2))); 223 224 foreach (var parent in tree.IterateNodesPrefix().ToArray()) { 225 for (int i = 0; i < parent.SubtreeCount; i++) { 226 var varChild = parent.GetSubtree(i) as VariableTreeNode; 227 var factorVarChild = parent.GetSubtree(i) as FactorVariableTreeNode; 228 if (varChild != null && factorSymbol.VariableNames.Contains(varChild.VariableName)) { 229 parent.RemoveSubtree(i); 230 var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode(); 231 factorTreeNode.VariableName = varChild.VariableName; 232 factorTreeNode.Weights = 233 factorTreeNode.Symbol.GetVariableValues(factorTreeNode.VariableName).Select(_ => 1.0).ToArray(); 234 // weight = 1.0 for each value 235 parent.InsertSubtree(i, factorTreeNode); 236 } else if (factorVarChild != null && factorSymbol.VariableNames.Contains(factorVarChild.VariableName)) { 237 if (factorSymbol.GetVariableValues(factorVarChild.VariableName).Count() != factorVarChild.Weights.Length) 238 throw new ArgumentException( 239 string.Format("Factor variable {0} needs exactly {1} weights", 240 factorVarChild.VariableName, 241 factorSymbol.GetVariableValues(factorVarChild.VariableName).Count())); 242 parent.RemoveSubtree(i); 243 var factorTreeNode = (FactorVariableTreeNode)factorSymbol.CreateTreeNode(); 244 factorTreeNode.VariableName = factorVarChild.VariableName; 245 factorTreeNode.Weights = factorVarChild.Weights; 246 parent.InsertSubtree(i, factorTreeNode); 247 } 248 } 249 } 209 250 210 251 if (!SymbolicRegressionConstantOptimizationEvaluator.CanOptimizeConstants(tree)) throw new ArgumentException("The optimizer does not support the specified model structure."); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestClassification.cs
r14185 r14836 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 132 133 133 134 #region random forest 134 protected override void Run( ) {135 protected override void Run(CancellationToken cancellationToken) { 135 136 double rmsError, relClassificationError, outOfBagRmsError, outOfBagRelClassificationError; 136 137 if (SetSeedRandomly) Seed = new System.Random().Next(); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/RandomForest/RandomForestRegression.cs
r14185 r14836 20 20 #endregion 21 21 22 using System.Threading; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 131 132 132 133 #region random forest 133 protected override void Run( ) {134 protected override void Run(CancellationToken cancellationToken) { 134 135 double rmsError, avgRelError, outOfBagRmsError, outOfBagAvgRelError; 135 136 if (SetSeedRandomly) Seed = new System.Random().Next(); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorClassification.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 143 144 144 145 #region support vector classification 145 protected override void Run( ) {146 protected override void Run(CancellationToken cancellationToken) { 146 147 IClassificationProblemData problemData = Problem.ProblemData; 147 148 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/SupportVectorMachine/SupportVectorRegression.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 151 152 152 153 #region support vector regression 153 protected override void Run( ) {154 protected override void Run(CancellationToken cancellationToken) { 154 155 IRegressionProblemData problemData = Problem.ProblemData; 155 156 IEnumerable<string> selectedInputVariables = problemData.AllowedInputVariables; -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TimeSeries/AutoregressiveModeling.cs
r14185 r14836 22 22 using System; 23 23 using System.Linq; 24 using System.Threading; 24 25 using HeuristicLab.Common; 25 26 using HeuristicLab.Core; … … 63 64 } 64 65 65 protected override void Run( ) {66 protected override void Run(CancellationToken cancellationToken) { 66 67 double rmsError, cvRmsError; 67 68 var solution = CreateAutoRegressiveSolution(Problem.ProblemData, TimeOffset, out rmsError, out cvRmsError); -
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/kMeans/KMeansClustering.cs
r14185 r14836 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using System.Threading; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 77 78 78 79 #region k-Means clustering 79 protected override void Run( ) {80 protected override void Run(CancellationToken cancellationToken) { 80 81 var solution = CreateKMeansSolution(Problem.ProblemData, K.Value, Restarts.Value); 81 82 Results.Add(new Result(KMeansSolutionResultName, "The k-Means clustering solution.", solution));
Note: See TracChangeset
for help on using the changeset viewer.