- Timestamp:
- 08/17/11 14:37:34 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs
r6613 r6666 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() { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs
r6520 r6666 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.IO;25 23 using System.Linq; 26 24 using HeuristicLab.Common; … … 36 34 37 35 public override IEnumerable<int> TrainingIndizes { 38 get { 39 return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); 40 } 36 get { return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start); } 41 37 } 42 38 public override IEnumerable<int> TestIndizes { 43 get { 44 return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); 45 } 39 get { return Enumerable.Range(TestPartition.Start, TestPartition.End - TestPartition.Start); } 40 } 41 42 private static ClassificationEnsembleProblemData emptyProblemData; 43 public static ClassificationEnsembleProblemData EmptyProblemData { 44 get { return emptyProblemData; } 45 } 46 47 static ClassificationEnsembleProblemData() { 48 var problemData = new ClassificationEnsembleProblemData(); 49 problemData.Parameters.Clear(); 50 problemData.Name = "Empty Classification ProblemData"; 51 problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded."; 52 problemData.isEmpty = true; 53 54 problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset())); 55 problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "")); 56 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 57 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 58 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 59 problemData.Parameters.Add(new FixedValueParameter<StringMatrix>(ClassNamesParameterName, "", new StringMatrix(0, 0).AsReadOnly())); 60 problemData.Parameters.Add(new FixedValueParameter<DoubleMatrix>(ClassificationPenaltiesParameterName, "", (DoubleMatrix)new DoubleMatrix(0, 0).AsReadOnly())); 61 emptyProblemData = problemData; 46 62 } 47 63 48 64 [StorableConstructor] 49 65 protected ClassificationEnsembleProblemData(bool deserializing) : base(deserializing) { } 66 protected ClassificationEnsembleProblemData(ClassificationEnsembleProblemData original, Cloner cloner) : base(original, cloner) { } 67 public override IDeepCloneable Clone(Cloner cloner) { 68 if (this == emptyProblemData) return emptyProblemData; 69 return new ClassificationEnsembleProblemData(this, cloner); 70 } 50 71 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 72 public ClassificationEnsembleProblemData() : base() { } 56 73 public ClassificationEnsembleProblemData(IClassificationProblemData classificationProblemData) 57 74 : base(classificationProblemData.Dataset, classificationProblemData.AllowedInputVariables, classificationProblemData.TargetVariable) { … … 61 78 this.TestPartition.End = classificationProblemData.TestPartition.End; 62 79 } 80 81 public ClassificationEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 82 : base(dataset, allowedInputVariables, targetVariable) { 83 } 63 84 } 64 85 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs
r6613 r6666 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); -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblemData.cs
r6654 r6666 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 … … 174 174 private static IEnumerable<string> defaultAllowedInputVariables; 175 175 private static string defaultTargetVariable; 176 177 private static 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) { } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r6581 r6666 33 33 [StorableClass] 34 34 public abstract class DataAnalysisProblemData : ParameterizedNamedItem, IDataAnalysisProblemData { 35 pr ivateconst string DatasetParameterName = "Dataset";36 pr ivateconst string InputVariablesParameterName = "InputVariables";37 pr ivateconst string TrainingPartitionParameterName = "TrainingPartition";38 pr ivateconst string TestPartitionParameterName = "TestPartition";35 protected const string DatasetParameterName = "Dataset"; 36 protected const string InputVariablesParameterName = "InputVariables"; 37 protected const string TrainingPartitionParameterName = "TrainingPartition"; 38 protected const string TestPartitionParameterName = "TestPartition"; 39 39 40 40 #region parameter properites … … 53 53 #endregion 54 54 55 #region propeties 55 #region properties 56 protected bool isEmpty = false; 57 public bool IsEmpty { 58 get { return isEmpty; } 59 } 56 60 public Dataset Dataset { 57 61 get { return DatasetParameter.Value; } … … 87 91 protected DataAnalysisProblemData(DataAnalysisProblemData original, Cloner cloner) 88 92 : base(original, cloner) { 93 isEmpty = original.isEmpty; 89 94 RegisterEventHandlers(); 90 95 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs
r6612 r6666 58 58 this.models = original.Models.Select(m => cloner.Clone(m)).ToList(); 59 59 } 60 61 public RegressionEnsembleModel() : this(Enumerable.Empty<IRegressionModel>()) { } 60 62 public RegressionEnsembleModel(IEnumerable<IRegressionModel> models) 61 63 : base() { -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleProblemData.cs
r6238 r6666 20 20 #endregion 21 21 22 using System;23 22 using System.Collections.Generic; 24 using System.IO;25 23 using System.Linq; 26 24 using HeuristicLab.Common; … … 47 45 } 48 46 47 private static RegressionEnsembleProblemData emptyProblemData; 48 public new static RegressionEnsembleProblemData EmptyProblemData { 49 get { return emptyProblemData; } 50 } 51 static RegressionEnsembleProblemData() { 52 var problemData = new RegressionEnsembleProblemData(); 53 problemData.Parameters.Clear(); 54 problemData.Name = "Empty Regression ProblemData"; 55 problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded."; 56 problemData.isEmpty = true; 57 58 problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset())); 59 problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "")); 60 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 61 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 62 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 63 emptyProblemData = problemData; 64 } 65 49 66 [StorableConstructor] 50 67 private RegressionEnsembleProblemData(bool deserializing) : base(deserializing) { } 68 private RegressionEnsembleProblemData(RegressionEnsembleProblemData original, Cloner cloner) : base(original, cloner) { } 69 public override IDeepCloneable Clone(Cloner cloner) { 70 if (this == emptyProblemData) return emptyProblemData; 71 return new RegressionEnsembleProblemData(this, cloner); 72 } 51 73 52 private RegressionEnsembleProblemData(RegressionEnsembleProblemData original, Cloner cloner) 53 : base(original, cloner) { 54 } 55 public override IDeepCloneable Clone(Cloner cloner) { return new RegressionEnsembleProblemData(this, cloner); } 56 74 public RegressionEnsembleProblemData() : base() { } 57 75 public RegressionEnsembleProblemData(IRegressionProblemData regressionProblemData) 58 76 : base(regressionProblemData.Dataset, regressionProblemData.AllowedInputVariables, regressionProblemData.TargetVariable) { … … 62 80 TestPartition.End = regressionProblemData.TestPartition.End; 63 81 } 82 public RegressionEnsembleProblemData(Dataset dataset, IEnumerable<string> allowedInputVariables, string targetVariable) 83 : base(dataset, allowedInputVariables, targetVariable) { 84 } 64 85 } 65 86 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs
r6613 r6666 35 35 [StorableClass] 36 36 [Item("Regression Ensemble Solution", "A regression solution that contains an ensemble of multiple regression models")] 37 // [Creatable("Data Analysis")]37 [Creatable("Data Analysis - Ensembles")] 38 38 public sealed class RegressionEnsembleSolution : RegressionSolution, IRegressionEnsembleSolution { 39 39 public new IRegressionEnsembleModel Model { 40 40 get { return (IRegressionEnsembleModel)base.Model; } 41 } 42 43 public new RegressionEnsembleProblemData ProblemData { 44 get { return (RegressionEnsembleProblemData)base.ProblemData; } 45 set { base.ProblemData = value; } 41 46 } 42 47 … … 59 64 private void AfterDeserialization() { 60 65 foreach (var model in Model.Models) { 61 IRegressionProblemData problemData = (IRegressionProblemData) ProblemData.Clone();66 IRegressionProblemData problemData = (IRegressionProblemData) ProblemData.Clone(); 62 67 problemData.TrainingPartition.Start = trainingPartitions[model].Start; 63 68 problemData.TrainingPartition.End = trainingPartitions[model].End; … … 82 87 83 88 regressionSolutions = cloner.Clone(original.regressionSolutions); 89 RegisterRegressionSolutionsEventHandler(); 90 } 91 92 public RegressionEnsembleSolution() 93 : base(new RegressionEnsembleModel(), RegressionEnsembleProblemData.EmptyProblemData) { 94 trainingPartitions = new Dictionary<IRegressionModel, IntRange>(); 95 testPartitions = new Dictionary<IRegressionModel, IntRange>(); 96 regressionSolutions = new ItemCollection<IRegressionSolution>(); 97 84 98 RegisterRegressionSolutionsEventHandler(); 85 99 } … … 203 217 #endregion 204 218 219 protected override void OnProblemDataChanged() { 220 IRegressionProblemData problemData = new RegressionProblemData(ProblemData.Dataset, 221 ProblemData.AllowedInputVariables, 222 ProblemData.TargetVariable); 223 problemData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 224 problemData.TrainingPartition.End = ProblemData.TrainingPartition.End; 225 problemData.TestPartition.Start = ProblemData.TestPartition.Start; 226 problemData.TestPartition.End = ProblemData.TestPartition.End; 227 228 foreach (var solution in RegressionSolutions) { 229 if (solution is RegressionEnsembleSolution) 230 solution.ProblemData = ProblemData; 231 else 232 solution.ProblemData = problemData; 233 } 234 foreach (var trainingPartition in trainingPartitions.Values) { 235 trainingPartition.Start = ProblemData.TrainingPartition.Start; 236 trainingPartition.End = ProblemData.TrainingPartition.End; 237 } 238 foreach (var testPartition in testPartitions.Values) { 239 testPartition.Start = ProblemData.TestPartition.Start; 240 testPartition.End = ProblemData.TestPartition.End; 241 } 242 243 base.OnProblemDataChanged(); 244 } 245 205 246 public void AddRegressionSolutions(IEnumerable<IRegressionSolution> solutions) { 206 solutions.OfType<RegressionEnsembleSolution>().SelectMany(ensemble => ensemble.RegressionSolutions);207 247 regressionSolutions.AddRange(solutions); 208 248 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblemData.cs
r6439 r6666 34 34 [Item("RegressionProblemData", "Represents an item containing all data defining a regression problem.")] 35 35 public class RegressionProblemData : DataAnalysisProblemData, IRegressionProblemData { 36 pr ivateconst string TargetVariableParameterName = "TargetVariable";36 protected const string TargetVariableParameterName = "TargetVariable"; 37 37 38 38 #region default data … … 68 68 private static string defaultTargetVariable; 69 69 70 private static RegressionProblemData emptyProblemData; 71 public static RegressionProblemData EmptyProblemData { 72 get { return emptyProblemData; } 73 } 74 70 75 static RegressionProblemData() { 71 76 defaultDataset = new Dataset(new string[] { "y", "x" }, kozaF1); … … 74 79 defaultAllowedInputVariables = new List<string>() { "x" }; 75 80 defaultTargetVariable = "y"; 81 82 var problemData = new RegressionProblemData(); 83 problemData.Parameters.Clear(); 84 problemData.Name = "Empty Regression ProblemData"; 85 problemData.Description = "This ProblemData acts as place holder before the correct problem data is loaded."; 86 problemData.isEmpty = true; 87 88 problemData.Parameters.Add(new FixedValueParameter<Dataset>(DatasetParameterName, "", new Dataset())); 89 problemData.Parameters.Add(new FixedValueParameter<ReadOnlyCheckedItemList<StringValue>>(InputVariablesParameterName, "")); 90 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TrainingPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 91 problemData.Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", (IntRange)new IntRange(0, 0).AsReadOnly())); 92 problemData.Parameters.Add(new ConstrainedValueParameter<StringValue>(TargetVariableParameterName, new ItemSet<StringValue>())); 93 emptyProblemData = problemData; 76 94 } 77 95 #endregion … … 91 109 } 92 110 93 94 111 protected RegressionProblemData(RegressionProblemData original, Cloner cloner) 95 112 : base(original, cloner) { 96 113 RegisterParameterEvents(); 97 114 } 98 public override IDeepCloneable Clone(Cloner cloner) { return new RegressionProblemData(this, cloner); } 115 public override IDeepCloneable Clone(Cloner cloner) { 116 if (this == emptyProblemData) return emptyProblemData; 117 return new RegressionProblemData(this, cloner); 118 } 99 119 100 120 public RegressionProblemData()
Note: See TracChangeset
for help on using the changeset viewer.