- Timestamp:
- 04/30/12 12:52:09 (13 years ago)
- Location:
- branches/ProblemInstancesRegressionAndClassification
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r7759 r7770 111 111 } 112 112 113 #region Import & Export 113 114 public void Load(ClassificationProblemData data) { 114 Name = data.Name; 115 Description = data.Description; 116 ProblemData = new ClassificationProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 117 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 118 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 119 ProblemData.TestPartition.Start = data.TestPartition.Start; 120 ProblemData.TestPartition.End = data.TestPartition.End; 121 OnReset(); 115 base.Load(data); 122 116 } 123 117 124 118 public ClassificationProblemData Export() { 125 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 126 claData.Name = Name; 127 claData.Description = Description; 128 claData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 129 claData.TrainingPartition.End = ProblemData.TrainingPartition.End; 130 claData.TestPartition.Start = ProblemData.TestPartition.Start; 131 claData.TestPartition.End = ProblemData.TestPartition.End; 132 return claData; 119 if (ProblemData is ClassificationProblemData) { 120 return (ClassificationProblemData)ProblemData; 121 } else { 122 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 123 return (ClassificationProblemData)base.Export(claData); 124 } 133 125 } 126 #endregion 134 127 } 135 128 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r7759 r7770 114 114 } 115 115 116 #region Import & Export 116 117 public void Load(RegressionProblemData data) { 117 Name = data.Name; 118 Description = data.Description; 119 ProblemData = new RegressionProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 120 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 121 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 122 ProblemData.TestPartition.Start = data.TestPartition.Start; 123 ProblemData.TestPartition.End = data.TestPartition.End; 124 OnReset(); 118 base.Load(data); 125 119 } 126 120 127 121 public RegressionProblemData Export() { 128 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 129 regData.Name = Name; 130 regData.Description = Description; 131 regData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 132 regData.TrainingPartition.End = ProblemData.TrainingPartition.End; 133 regData.TestPartition.Start = ProblemData.TestPartition.Start; 134 regData.TestPartition.End = ProblemData.TestPartition.End; 135 return regData; 122 if (ProblemData is RegressionProblemData) 123 return (RegressionProblemData)ProblemData; 124 else { 125 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 126 return (RegressionProblemData)base.Export(regData); 127 } 136 128 } 129 #endregion 137 130 } 138 131 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r7758 r7770 319 319 } 320 320 } 321 322 #region Import & Export 323 protected void Load(T data) { 324 Name = data.Name; 325 Description = data.Description; 326 ProblemData = data; 327 OnReset(); 328 } 329 330 protected T Export(T data) { 331 data.Name = Name; 332 data.Description = Description; 333 data.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 334 data.TrainingPartition.End = ProblemData.TrainingPartition.End; 335 data.TestPartition.Start = ProblemData.TestPartition.Start; 336 data.TestPartition.End = ProblemData.TestPartition.End; 337 return data; 338 } 339 #endregion 321 340 } 322 341 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationProblem.cs
r7759 r7770 43 43 } 44 44 45 #region Import & Export 45 46 public void Load(ClassificationProblemData data) { 46 Name = data.Name; 47 Description = data.Description; 48 ProblemData = new ClassificationProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 49 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 50 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 51 ProblemData.TestPartition.Start = data.TestPartition.Start; 52 ProblemData.TestPartition.End = data.TestPartition.End; 53 OnReset(); 47 base.Load(data); 54 48 } 55 49 56 50 public ClassificationProblemData Export() { 57 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 58 claData.Name = Name; 59 claData.Description = Description; 60 claData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 61 claData.TrainingPartition.End = ProblemData.TrainingPartition.End; 62 claData.TestPartition.Start = ProblemData.TestPartition.Start; 63 claData.TestPartition.End = ProblemData.TestPartition.End; 64 return claData; 51 if (ProblemData is ClassificationProblemData) { 52 return (ClassificationProblemData)ProblemData; 53 } else { 54 ClassificationProblemData claData = new ClassificationProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 55 return (ClassificationProblemData)base.Export(claData); 56 } 65 57 } 58 #endregion 66 59 } 67 60 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblem.cs
r7758 r7770 90 90 if (handler != null) handler(this, EventArgs.Empty); 91 91 } 92 93 #region Import & Export 94 protected void Load(T data) { 95 Name = data.Name; 96 Description = data.Description; 97 ProblemData = data; 98 OnReset(); 99 } 100 101 protected T Export(T data) { 102 data.Name = Name; 103 data.Description = Description; 104 data.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 105 data.TrainingPartition.End = ProblemData.TrainingPartition.End; 106 data.TestPartition.Start = ProblemData.TestPartition.Start; 107 data.TestPartition.End = ProblemData.TestPartition.End; 108 return data; 109 } 110 #endregion 92 111 } 93 112 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionProblem.cs
r7759 r7770 43 43 } 44 44 45 #region Import & Export 45 46 public void Load(RegressionProblemData data) { 46 Name = data.Name; 47 Description = data.Description; 48 ProblemData = new RegressionProblemData(data.Dataset, data.AllowedInputVariables, data.TargetVariable); 49 ProblemData.TrainingPartition.Start = data.TrainingPartition.Start; 50 ProblemData.TrainingPartition.End = data.TrainingPartition.End; 51 ProblemData.TestPartition.Start = data.TestPartition.Start; 52 ProblemData.TestPartition.End = data.TestPartition.End; 53 OnReset(); 47 base.Load(data); 54 48 } 55 49 56 50 public RegressionProblemData Export() { 57 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 58 regData.Name = Name; 59 regData.Description = Description; 60 regData.TrainingPartition.Start = ProblemData.TrainingPartition.Start; 61 regData.TrainingPartition.End = ProblemData.TrainingPartition.End; 62 regData.TestPartition.Start = ProblemData.TestPartition.Start; 63 regData.TestPartition.End = ProblemData.TestPartition.End; 64 return regData; 51 if (ProblemData is RegressionProblemData) { 52 return (RegressionProblemData)ProblemData; 53 } else { 54 RegressionProblemData regData = new RegressionProblemData(ProblemData.Dataset, ProblemData.AllowedInputVariables, ProblemData.TargetVariable); 55 return (RegressionProblemData)base.Export(regData); 56 } 65 57 } 58 #endregion 66 59 } 67 60 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Regression/3.4/ValueGenerator.cs
r7759 r7770 20 20 #endregion 21 21 22 23 22 using System; 24 23 using System.Collections.Generic; 25 24 using System.Linq; 26 25 using HeuristicLab.Random; 26 27 27 namespace HeuristicLab.Problems.Instances.Regression { 28 28 public static class ValueGenerator { … … 45 45 } 46 46 47 public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) { 47 // iterative approach 48 public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> lists) { 49 List<List<double>> allCombinations = new List<List<double>>(); 50 if (lists.Count < 1) { 51 return allCombinations; 52 } 53 54 List<IEnumerator<double>> enumerators = new List<IEnumerator<double>>(); 55 foreach (var list in lists) { 56 enumerators.Add(list.GetEnumerator()); 57 } 58 59 bool finished = !enumerators.All(x => x.MoveNext()); 60 61 while (!finished) { 62 allCombinations.Add(GetCurrentCombination(enumerators)); 63 finished = MoveNext(enumerators, lists); 64 } 65 66 IEnumerable<IEnumerable<double>> res = (from i in Enumerable.Range(0, lists.Count) 67 select (from list in allCombinations 68 select list.ElementAt(i))); 69 return res; 70 } 71 72 private static bool MoveNext(List<IEnumerator<double>> enumerators, List<List<double>> lists) { 73 int cur = enumerators.Count - 1; 74 while (cur >= 0 && !enumerators[cur].MoveNext()) { 75 enumerators[cur] = lists[cur].GetEnumerator(); 76 enumerators[cur].MoveNext(); 77 cur--; 78 } 79 return cur < 0; 80 } 81 82 private static List<double> GetCurrentCombination(List<IEnumerator<double>> enumerators) { 83 List<double> combination = new List<double>(); 84 foreach (var enumerator in enumerators) { 85 combination.Add(enumerator.Current); 86 } 87 return combination; 88 } 89 90 //recursive approach 91 /*public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> lists) { 92 int cur = 0; 93 List<double> curCombination = new List<double>(); 94 List<List<double>> allCombinations = new List<List<double>>(); 95 if (lists.Count() > cur) { 96 foreach (var item in lists[cur]) { 97 curCombination.Clear(); 98 curCombination.Add(item); 99 GetCombination(lists, cur + 1, curCombination, allCombinations); 100 } 101 } 102 103 IEnumerable<IEnumerable<double>> res = (from i in Enumerable.Range(0, lists.Count) 104 select (from list in allCombinations 105 select list.ElementAt(i))); 106 107 return res; 108 } 109 110 private static void GetCombination(List<List<double>> lists, int cur, List<double> curCombinations, List<List<double>> allCombinations) { 111 if (lists.Count > cur) { 112 foreach (var item in lists[cur]) { 113 if (curCombinations.Count > cur) { 114 curCombinations.RemoveAt(cur); 115 } 116 curCombinations.Add(item); 117 GetCombination(lists, cur + 1, curCombinations, allCombinations); 118 } 119 } else { 120 allCombinations.Add(new List<double>(curCombinations)); 121 } 122 } */ 123 124 //original 125 /*public static IEnumerable<IEnumerable<double>> GenerateAllCombinationsOfValuesInLists(List<List<double>> sets) { 48 126 49 127 var combinations = new List<List<double>>(); … … 69 147 70 148 return newCombinations.ToList(); 71 } 149 } */ 72 150 } 73 151 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceConsumerView.cs
r7698 r7770 61 61 } 62 62 63 private IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() { 64 var consumerTypes = Content.GetType().GetInterfaces() 65 .Where(x => x.IsGenericType 66 && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>)); 67 68 if (consumerTypes.Any()) { 69 var instanceTypes = consumerTypes 70 .Select(x => x.GetGenericArguments().First()) 71 .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x)); 72 73 foreach (var type in instanceTypes) { 74 foreach (var provider in ApplicationManager.Manager.GetInstances(type)) 75 yield return (IProblemInstanceProvider)provider; 76 } 77 } 78 } 79 63 80 public bool ContainsProviders() { 64 81 return problemInstanceProviderComboBox.Items.Count > 0; … … 102 119 } 103 120 104 private IEnumerable<IProblemInstanceProvider> GetProblemInstanceProviders() { 105 var consumerTypes = Content.GetType().GetInterfaces() 106 .Where(x => x.IsGenericType 107 && x.GetGenericTypeDefinition() == typeof(IProblemInstanceConsumer<>)); 108 109 if (consumerTypes.Any()) { 110 var instanceTypes = consumerTypes 111 .Select(x => x.GetGenericArguments().First()) 112 .Select(x => typeof(IProblemInstanceProvider<>).MakeGenericType(x)); 113 114 foreach (var type in instanceTypes) { 115 foreach (var provider in ApplicationManager.Manager.GetInstances(type)) 116 yield return (IProblemInstanceProvider)provider; 117 } 118 } 119 } 120 121 #region ToolTip 121 122 private void SetTooltip() { 122 123 toolTip.SetToolTip(problemInstanceProviderComboBox, GetProviderToolTip()); … … 143 144 return toolTip; 144 145 } 146 #endregion 145 147 } 146 148 } -
branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.Instances.Views/3.4/ProblemInstanceProviderViewGeneric.cs
r7758 r7770 39 39 } 40 40 41 #region Importer & Exporter 41 42 protected IProblemInstanceConsumer<T> GenericConsumer { get { return Consumer as IProblemInstanceConsumer<T>; } } 42 43 protected IProblemInstanceConsumer consumer; … … 58 59 } 59 60 } 61 #endregion 60 62 61 63 public ProblemInstanceProviderViewGeneric() { … … 93 95 protected virtual void loadButton_Click(object sender, EventArgs e) { 94 96 var descriptor = (IDataDescriptor)instancesComboBox.SelectedItem; 95 varinstance = Content.LoadData(descriptor);97 T instance = Content.LoadData(descriptor); 96 98 try { 97 99 GenericConsumer.Load(instance);
Note: See TracChangeset
for help on using the changeset viewer.