- Timestamp:
- 01/22/14 16:53:31 (11 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3
- Files:
-
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/HeuristicLab.DataPreprocessing-3.3.csproj
r10380 r10383 95 95 <Compile Include="Interfaces\IManipulationLogic.cs" /> 96 96 <Compile Include="Interfaces\ITransformationLogic.cs" /> 97 <Compile Include="Pr eprocessingCloner.cs" />97 <Compile Include="ProblemDataCreator.cs" /> 98 98 <Compile Include="Views\FilterView.cs"> 99 99 <SubType>UserControl</SubType> -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/DataPreprocessorStarter.cs
r10307 r10383 34 34 public void Start(IDataAnalysisProblemData problemData, View currentView) { 35 35 IAlgorithm algorithm; 36 I Problem problem;36 IDataAnalysisProblem problem; 37 37 IItem parentItem = GetMostOuterContent(currentView, out algorithm, out problem); 38 var context = new PreprocessingContext(problemData, parentItem,algorithm, problem);38 var context = new PreprocessingContext(problemData, algorithm, problem); 39 39 MainFormManager.MainForm.ShowContent(context); 40 40 } 41 41 42 private IItem GetMostOuterContent(Control control, out IAlgorithm algorithm, out I Problem problem) {42 private IItem GetMostOuterContent(Control control, out IAlgorithm algorithm, out IDataAnalysisProblem problem) { 43 43 algorithm = null; 44 44 problem = null; … … 51 51 algorithm = (IAlgorithm)itemView.Content; 52 52 } 53 if (itemView.Content is I Problem) {54 problem = (I Problem)itemView.Content;53 if (itemView.Content is IDataAnalysisProblem) { 54 problem = (IDataAnalysisProblem)itemView.Content; 55 55 } 56 56 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/PreprocessingContext.cs
r10307 r10383 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 27 28 namespace HeuristicLab.DataPreprocessing { 28 29 [Item("PreprocessingContext", "PreprocessingContext")] 29 public class PreprocessingContext : Item, IPreprocessingContext { 30 public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IItem parentItem, IAlgorithm algorithm, IProblem problem) { 30 public class PreprocessingContext 31 : Item, IPreprocessingContext { 32 33 public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) { 31 34 Data = new PreprocessingData(dataAnalysisProblemData); 32 ParentItem = parentItem;33 35 DataAnalysisProblemData = dataAnalysisProblemData; 34 36 Algorithm = algorithm; … … 39 41 : base(original, cloner) { 40 42 Data = cloner.Clone(original.Data); 41 ParentItem = original.ParentItem;42 43 DataAnalysisProblemData = original.DataAnalysisProblemData; 43 44 Algorithm = original.Algorithm; … … 47 48 public IPreprocessingData Data { get; private set; } 48 49 49 /// <summary>50 /// Parent algorithm, if available, or problem.51 /// </summary>52 public IItem ParentItem { get; private set; }53 54 50 public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; } 55 51 56 52 public IAlgorithm Algorithm { get; private set; } 57 53 58 public I Problem Problem { get; private set; }54 public IDataAnalysisProblem Problem { get; private set; } 59 55 60 56 public override IDeepCloneable Clone(Cloner cloner) { 61 57 return new PreprocessingContext(this, cloner); 62 58 } 59 60 public IItem ExportAlgorithmOrProblem() { 61 if (Algorithm != null) { 62 return ExportAlgorithm(); 63 } else { 64 return ExportProblem(); 65 } 66 } 67 68 public IProblem ExportProblem() { 69 return Export(Problem, SetupProblem); 70 } 71 72 private IDataAnalysisProblem SetupProblem(IProblem problem) { 73 return (IDataAnalysisProblem)problem; 74 } 75 76 public IAlgorithm ExportAlgorithm() { 77 return Export(Algorithm, SetupAlgorithm); 78 } 79 80 private IDataAnalysisProblem SetupAlgorithm(IAlgorithm algorithm) { 81 algorithm.Name = "Cloned " + algorithm.Name; 82 algorithm.Runs.Clear(); 83 84 return (IDataAnalysisProblem)algorithm.Problem; 85 } 86 87 private T Export<T>(T original, Func<T, IDataAnalysisProblem> setup) where T : IItem { 88 var creator = new ProblemDataCreator(this); 89 var data = creator.CreateProblemData(); 90 91 var clone = (T)original.Clone(new Cloner()); 92 93 var problem = setup(clone); 94 problem.ProblemDataParameter.ActualValue = data; 95 problem.Name = "Cloned " + problem.Name; 96 97 return clone; 98 } 63 99 } 64 100 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Implementations/StatisticsLogic.cs
r10381 r10383 1 1 using System; 2 using System.Collections.Generic; 2 3 using System.Linq; 3 4 using HeuristicLab.Common; 4 using System.Collections.Generic;5 5 6 6 namespace HeuristicLab.DataPreprocessing { … … 75 75 } 76 76 77 public DateTime GetMedianDateTime(int columnIndex) 78 { 77 public DateTime GetMedianDateTime(int columnIndex) { 79 78 DateTime median = new DateTime(); 80 if (preprocessingData.IsType<DateTime>(columnIndex)) 81 { 82 median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median()); 79 if (preprocessingData.IsType<DateTime>(columnIndex)) { 80 median = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Median()); 83 81 } 84 82 return median; 85 83 } 86 84 87 public DateTime GetAverageDateTime(int columnIndex) 88 { 85 public DateTime GetAverageDateTime(int columnIndex) { 89 86 DateTime avg = new DateTime(); 90 if (preprocessingData.IsType<DateTime>(columnIndex)) 91 { 92 avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average()); 87 if (preprocessingData.IsType<DateTime>(columnIndex)) { 88 avg = GetSecondsAsDateTime(GetDateTimeAsSeconds(columnIndex).Average()); 93 89 } 94 90 return avg; … … 107 103 public double GetStandardDeviation(int columnIndex) { 108 104 double stdDev = double.NaN; 105 //TODO: fix me 106 /* 109 107 if (preprocessingData.IsType<double>(columnIndex)) { 110 108 stdDev = preprocessingData.GetValues<double>(columnIndex).StandardDeviation(); … … 113 111 stdDev = GetDateTimeAsSeconds(variableName).StandardDeviation(); 114 112 } 113 */ 115 114 return stdDev; 116 115 } 117 116 118 117 public double GetVariance(int columnIndex) { 119 double variance = double.NaN; 120 118 double variance = double.NaN; 119 //TODO: fix me 120 /* 121 121 if (preprocessingData.IsType<double>(columnIndex)) { 122 122 variance = preprocessingData.GetValues<double>(columnIndex).Variance(); … … 125 125 variance = GetDateTimeAsSeconds(variableName).Variance(); 126 126 } 127 */ 127 128 return variance; 128 129 } … … 161 162 } 162 163 163 private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) 164 { 165 return preprocessingData.GetValues<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond); 164 private IEnumerable<double> GetDateTimeAsSeconds(int columnIndex) { 165 return preprocessingData.GetValues<DateTime>(columnIndex).Select(x => (double)x.Ticks / TimeSpan.TicksPerSecond); 166 166 } 167 167 168 private DateTime GetSecondsAsDateTime(double seconds) 169 { 170 DateTime dateTime = new DateTime(); 171 return dateTime.Add(new TimeSpan(0, 0, (int)seconds)); 168 private DateTime GetSecondsAsDateTime(double seconds) { 169 DateTime dateTime = new DateTime(); 170 return dateTime.Add(new TimeSpan(0, 0, (int)seconds)); 172 171 } 173 172 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Interfaces/IPreprocessingContext.cs
r10307 r10383 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Core; 23 24 using HeuristicLab.Optimization; … … 25 26 26 27 namespace HeuristicLab.DataPreprocessing { 27 public interface IPreprocessingContext : IItem { 28 public interface IPreprocessingContext 29 : IItem { 30 28 31 IPreprocessingData Data { get; } 29 32 30 /// <summary> 31 /// Parent algorithm, if available, or problem. 32 /// </summary> 33 IItem ParentItem { get; } 34 33 [Obsolete] 35 34 IDataAnalysisProblemData DataAnalysisProblemData { get; } 36 35 37 36 IAlgorithm Algorithm { get; } 38 37 39 IProblem Problem { get; } 38 IDataAnalysisProblem Problem { get; } 39 40 IItem ExportAlgorithmOrProblem(); 41 42 IAlgorithm ExportAlgorithm(); 43 44 IProblem ExportProblem(); 40 45 } 41 46 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Plugin.cs.frame
r10250 r10383 28 28 [Plugin("HeuristicLab.DataPreprocessing", "3.3.9.$WCREV$")] 29 29 [PluginFile("HeuristicLab.DataPreprocessing-3.3.dll", PluginFileType.Assembly)] 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] 30 31 [PluginDependency("HeuristicLab.Common", "3.3")] 31 32 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/ProblemDataCreator.cs
r10382 r10383 20 20 #endregion 21 21 22 using System; 22 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 25 26 using HeuristicLab.Data; 26 using HeuristicLab.Optimization;27 27 using HeuristicLab.Problems.DataAnalysis; 28 28 29 29 namespace HeuristicLab.DataPreprocessing { 30 internal class Pr eprocessingCloner {30 internal class ProblemDataCreator { 31 31 32 32 private readonly IPreprocessingContext context; 33 33 34 public Pr eprocessingCloner(IPreprocessingContext context) {34 public ProblemDataCreator(IPreprocessingContext context) { 35 35 this.context = context; 36 36 } 37 37 38 public IItem GenerateAlteredClone(IItem obj) { 39 IPreprocessingData data = context.Data; 38 public IDataAnalysisProblemData CreateProblemData() { 40 39 41 Dataset dataset = data.ExportToDataset(); 42 var variables = new CheckedItemList<StringValue>(data.VariableNames.Select(s => new StringValue(s))).AsReadOnly(); 40 IDataAnalysisProblemData problemData = CloneProblemDataWithDataset(); 43 41 42 SetTrainingAndTestPartition(problemData); 43 44 if (problemData is RegressionProblemData) { 45 //SetRegressionData((RegressionProblemData)problemData); 46 } else if (problemData is ClassificationProblemData) { 47 //SetClassificationData((ClassificationProblemData)problemData); 48 } else if (problemData is ClusteringProblemData) { 49 throw new NotImplementedException(); 50 } 51 52 return problemData; 53 } 54 55 private IDataAnalysisProblemData CloneProblemDataWithDataset() { 44 56 var cloner = new Cloner(); 45 57 46 cloner.RegisterClonedObject(context.DataAnalysisProblemData.Dataset, dataset); 47 cloner.RegisterClonedObject(context.DataAnalysisProblemData.TrainingPartition, data.TrainingPartition); 48 cloner.RegisterClonedObject(context.DataAnalysisProblemData.TestPartition, data.TestPartition); 49 cloner.RegisterClonedObject(context.DataAnalysisProblemData.InputVariables, variables); 50 if (context.Algorithm != null) { 51 cloner.RegisterClonedObject(context.Algorithm.Runs, new RunCollection { OptimizerName = context.Algorithm.Name }); 58 var problemData = context.Problem.ProblemData; 59 60 Dataset dataset = context.Data.ExportToDataset(); 61 62 cloner.RegisterClonedObject(problemData.Dataset, dataset); 63 64 return cloner.Clone(problemData); 65 } 66 67 private void SetTrainingAndTestPartition(IDataAnalysisProblemData problemData) { 68 var ppData = context.Data; 69 70 problemData.TrainingPartition.Start = ppData.TrainingPartition.Start; 71 problemData.TrainingPartition.End = ppData.TrainingPartition.End; 72 problemData.TestPartition.Start = ppData.TestPartition.Start; 73 problemData.TestPartition.End = ppData.TestPartition.End; 74 } 75 76 private void SetRegressionData(RegressionProblemData regressionProblemData) { 77 SetInputVariables(regressionProblemData, regressionProblemData.TargetVariable); 78 SetTargetVariable(regressionProblemData.TargetVariableParameter); 79 } 80 81 private void SetClassificationData(ClassificationProblemData classificationProblemData) { 82 SetInputVariables(classificationProblemData, classificationProblemData.TargetVariable); 83 SetTargetVariable(classificationProblemData.TargetVariableParameter); 84 } 85 86 private void SetInputVariables(DataAnalysisProblemData problemData, string targetVariable) { 87 //TODO: InputVariables Set is Readonly 88 89 problemData.InputVariables.Clear(); 90 91 foreach (string variable in context.Data.VariableNames) { 92 problemData.InputVariables.Add(new StringValue(variable), variable != targetVariable); 93 } 94 } 95 96 private void SetTargetVariable(IConstrainedValueParameter<StringValue> targetVariableParameter) { 97 string oldTarget = targetVariableParameter.Value.Value; 98 99 var validValues = targetVariableParameter.ValidValues; 100 validValues.Clear(); 101 102 foreach (string variable in context.Data.VariableNames.Where(x => context.Data.IsType<double>(x))) { 103 validValues.Add(new StringValue(variable)); 52 104 } 53 105 54 return cloner.Clone(obj);106 targetVariableParameter.ActualValue = validValues.FirstOrDefault(v => v.Value == oldTarget); 55 107 } 56 108 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.3/Views/DataPreprocessingView.cs
r10377 r10383 8 8 namespace HeuristicLab.DataPreprocessing { 9 9 [View("DataPreprocessing View")] 10 [Content(typeof( PreprocessingContext), true)]10 [Content(typeof(IPreprocessingContext), true)] 11 11 public partial class DataPreprocessingView : ItemView { 12 12 … … 97 97 98 98 private void exportProblemButton_Click(object sender, EventArgs e) { 99 var cloner = new PreprocessingCloner(Content); 100 var alteredClone = cloner.GenerateAlteredClone(Content.Problem); 99 var problem = Content.ExportProblem(); 101 100 102 101 var saveFileDialog = new SaveFileDialog { … … 107 106 }; 108 107 109 var content = alteredCloneas IStorableContent;108 var content = problem as IStorableContent; 110 109 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 111 110 bool compressed = saveFileDialog.FilterIndex != 1; … … 115 114 116 115 private void applyInNewTabButton_Click(object sender, EventArgs e) { 117 var cloner = new PreprocessingCloner(Content); 118 var item = cloner.GenerateAlteredClone(Content.ParentItem); 116 var item = Content.ExportAlgorithmOrProblem(); 119 117 120 118 MainFormManager.MainForm.ShowContent(item);
Note: See TracChangeset
for help on using the changeset viewer.