Changeset 6685 for branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification
- Timestamp:
- 08/31/11 11:52:11 (13 years ago)
- Location:
- branches/GeneralizedQAP
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GeneralizedQAP
- Property svn:mergeinfo changed
/trunk/sources (added) merged: 6648-6649,6652-6656,6661-6674,6676-6681,6684
- Property svn:mergeinfo changed
-
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis (added) merged: 6653-6654,6661,6666,6672
- Property svn:mergeinfo changed
-
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r6613 r6685 46 46 this.models = original.Models.Select(m => cloner.Clone(m)).ToList(); 47 47 } 48 49 public ClassificationEnsembleModel() : this(Enumerable.Empty<IClassificationModel>()) { } 48 50 public ClassificationEnsembleModel(IEnumerable<IClassificationModel> models) 49 51 : base() { -
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r6520 r6685 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.IO;25 using System.Linq;26 23 using HeuristicLab.Common; 27 24 using HeuristicLab.Core; … … 35 32 public class ClassificationEnsembleProblemData : ClassificationProblemData { 36 33 37 public override IEnumerable<int> TrainingIndizes { 38 get { 39 return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); 40 } 34 public override bool IsTrainingSample(int index) { 35 return index >= 0 && index < Dataset.Rows && 36 TrainingPartition.Start <= index && index < TrainingPartition.End; 41 37 } 42 public override IEnumerable<int> TestIndizes { 43 get { 44 return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); 45 } 38 39 public override bool IsTestSample(int index) { 40 return index >= 0 && index < Dataset.Rows && 41 TestPartition.Start <= index && index < TestPartition.End; 42 } 43 44 private static readonly ClassificationEnsembleProblemData emptyProblemData; 45 public static ClassificationEnsembleProblemData EmptyProblemData { 46 get { return emptyProblemData; } 47 } 48 49 static ClassificationEnsembleProblemData() { 50 var problemData = new ClassificationEnsembleProblemData(); 51 problemData.Parameters.Clear(); 52 problemData.Name = "Empty Classification ProblemData"; 53 problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded."; 54 problemData.isEmpty = true; 55 56 problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset())); 57 problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "")); 58 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 59 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 60 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 61 problemData.Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix(0, 0).AsReadOnly())); 62 problemData.Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "", (DoubleMatrix)new DoubleMatrix(0, 0).AsReadOnly())); 63 emptyProblemData = problemData; 46 64 } 47 65 48 66 [StorableConstructor] 49 67 protected ClassificationEnsembleProblemData(bool deserializing) : base(deserializing) { } 68 protected ClassificationEnsembleProblemData(ClassificationEnsembleProblemData original, Cloner cloner) : base(original, cloner) { } 69 public override IDeepCloneable Clone(Cloner cloner) { 70 if (this == emptyProblemData) return emptyProblemData; 71 return new ClassificationEnsembleProblemData(this, cloner); 72 } 50 73 51 protected ClassificationEnsembleProblemData(ClassificationEnsembleProblemData original, Cloner cloner) 52 : base(original, cloner) { 53 } 54 public override IDeepCloneable Clone(Cloner cloner) { return new ClassificationEnsembleProblemData(this, cloner); } 55 74 public ClassificationEnsembleProblemData() : base() { } 56 75 public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData) 57 76 : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { … … 61 80 this.TestPartition.End = classificationProblemData.TestPartition.End; 62 81 } 82 83 public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 84 : base(dataset, allowedInputVariables, targetVariable) { 85 } 63 86 } 64 87 } -
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r6613 r6685 35 35 [StorableClass] 36 36 [Item("Classification Ensemble Solution", "A classification solution that contains an ensemble of multiple classification models")] 37 // [Creatable("Data Analysis")]37 [Creatable("Data Analysis - Ensembles")] 38 38 public sealed class ClassificationEnsembleSolution : ClassificationSolution, IClassificationEnsembleSolution { 39 39 public new IClassificationEnsembleModel Model { 40 40 get { return (IClassificationEnsembleModel)base.Model; } 41 } 42 public new ClassificationEnsembleProblemData ProblemData { 43 get { return (ClassificationEnsembleProblemData)base.ProblemData; } 44 set { base.ProblemData = value; } 41 45 } 42 46 … … 82 86 83 87 classificationSolutions = cloner.Clone(original.classificationSolutions); 88 RegisterClassificationSolutionsEventHandler(); 89 } 90 91 public ClassificationEnsembleSolution() 92 : base(new ClassificationEnsembleModel(), ClassificationEnsembleProblemData.EmptyProblemData) { 93 trainingPartitions = new Dictionary<IClassificationModel, IntRange>(); 94 testPartitions = new Dictionary<IClassificationModel, IntRange>(); 95 classificationSolutions = new ItemCollection<IClassificationSolution>(); 96 84 97 RegisterClassificationSolutionsEventHandler(); 85 98 } … … 208 221 #endregion 209 222 223 protected override void OnProblemDataChanged() { 224 IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset, 225 ProblemData.AllowedInputVariables, 226 ProblemData.TargetVariable); 227 problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 228 problemData.TrainingPartition.End = ProblemData.TrainingPartition.End; 229 problemData.TestPartition.Start = ProblemData.TestPartition.Start; 230 problemData.TestPartition.End = ProblemData.TestPartition.End; 231 232 foreach (var solution in ClassificationSolutions) { 233 if (solution is ClassificationEnsembleSolution) 234 solution.ProblemData = ProblemData; 235 else 236 solution.ProblemData = problemData; 237 } 238 foreach (var trainingPartition in trainingPartitions.Values) { 239 trainingPartition.Start = ProblemData.TrainingPartition.Start; 240 trainingPartition.End = ProblemData.TrainingPartition.End; 241 } 242 foreach (var testPartition in testPartitions.Values) { 243 testPartition.Start = ProblemData.TestPartition.Start; 244 testPartition.End = ProblemData.TestPartition.End; 245 } 246 247 base.OnProblemDataChanged(); 248 } 249 210 250 public void AddClassificationSolutions(IEnumerable<IClassificationSolution> solutions) { 211 251 classificationSolutions.AddRange(solutions); -
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r6440 r6685 34 34 [Item("ClassificationProblemData", "Represents an item containing all data defining a classification problem.")] 35 35 public class ClassificationProblemData : DataAnalysisProblemData, IClassificationProblemData { 36 pr ivateconst string TargetVariableParameterName = "TargetVariable";37 pr ivateconst string ClassNamesParameterName = "ClassNames";38 pr ivateconst string ClassificationPenaltiesParameterName = "ClassificationPenalties";39 pr ivateconst int MaximumNumberOfClasses = 20;40 pr ivateconst int InspectedRowsToDetermineTargets = 500;36 protected const string TargetVariableParameterName = "TargetVariable"; 37 protected const string ClassNamesParameterName = "ClassNames"; 38 protected const string ClassificationPenaltiesParameterName = "ClassificationPenalties"; 39 protected const int MaximumNumberOfClasses = 20; 40 protected const int InspectedRowsToDetermineTargets = 500; 41 41 42 42 #region default data … … 171 171 {1176881,7,5,3,7,4,10,7,5,5,4 } 172 172 }; 173 private static Dataset defaultDataset; 174 private static IEnumerable<string> defaultAllowedInputVariables; 175 private static string defaultTargetVariable; 173 private static readonly Dataset defaultDataset; 174 private static readonly IEnumerable<string> defaultAllowedInputVariables; 175 private static readonly string defaultTargetVariable; 176 177 private static readonly ClassificationProblemData emptyProblemData; 178 public static ClassificationProblemData EmptyProblemData { 179 get { return EmptyProblemData; } 180 } 181 176 182 static ClassificationProblemData() { 177 183 defaultDataset = new Dataset(defaultVariableNames, defaultData); … … 181 187 defaultAllowedInputVariables = defaultVariableNames.Except(new List<string>() { "sample", "class" }); 182 188 defaultTargetVariable = "class"; 189 190 var problemData = new ClassificationProblemData(); 191 problemData.Parameters.Clear(); 192 problemData.Name = "Empty Classification ProblemData"; 193 problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded."; 194 problemData.isEmpty = true; 195 196 problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset())); 197 problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "")); 198 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 199 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 200 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 201 problemData.Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix(0, 0).AsReadOnly())); 202 problemData.Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "", (DoubleMatrix)new DoubleMatrix(0, 0).AsReadOnly())); 203 emptyProblemData = problemData; 183 204 } 184 205 #endregion … … 249 270 RegisterParameterEvents(); 250 271 } 251 public override IDeepCloneable Clone(Cloner cloner) { return new ClassificationProblemData(this, cloner); } 272 public override IDeepCloneable Clone(Cloner cloner) { 273 if (this == emptyProblemData) return emptyProblemData; 274 return new ClassificationProblemData(this, cloner); 275 } 252 276 253 277 public ClassificationProblemData() : this(defaultDataset, defaultAllowedInputVariables, defaultTargetVariable) { } … … 267 291 private static IEnumerable<string> CheckVariablesForPossibleTargetVariables(Dataset dataset) { 268 292 int maxSamples = Math.Min(InspectedRowsToDetermineTargets, dataset.Rows); 269 var validTargetVariables = from v in dataset.VariableNames270 let DistinctValues = dataset.GetVariableValues(v)271 .Take(maxSamples)272 .Distinct()273 .Count()274 where DistinctValues < MaximumNumberOfClasses275 select v;293 var validTargetVariables = (from v in dataset.VariableNames 294 let distinctValues = dataset.GetEnumeratedVariableValues(v) 295 .Take(maxSamples) 296 .Distinct() 297 .Count() 298 where distinctValues < MaximumNumberOfClasses 299 select v).ToArray(); 276 300 277 301 if (!validTargetVariables.Any()) … … 283 307 284 308 private void ResetTargetVariableDependentMembers() { 285 Der gisterParameterEvents();309 DeregisterParameterEvents(); 286 310 287 311 classNames = null; … … 357 381 ClassificationPenaltiesParameter.Value.ItemChanged += new EventHandler<EventArgs<int, int>>(MatrixParameter_ItemChanged); 358 382 } 359 private void Der gisterParameterEvents() {383 private void DeregisterParameterEvents() { 360 384 TargetVariableParameter.ValueChanged -= new EventHandler(TargetVariableParameter_ValueChanged); 361 385 ClassNamesParameter.Value.Reset -= new EventHandler(Parameter_ValueChanged); -
branches/GeneralizedQAP/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r6589 r6685 40 40 public new IClassificationProblemData ProblemData { 41 41 get { return (IClassificationProblemData)base.ProblemData; } 42 protectedset { base.ProblemData = value; }42 set { base.ProblemData = value; } 43 43 } 44 44
Note: See TracChangeset
for help on using the changeset viewer.