- Timestamp:
- 06/11/14 12:36:39 (10 years ago)
- Location:
- branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ChartLogic.cs
r10973 r10978 140 140 public DataRow CreateSelectedDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) { 141 141 142 IDictionary<int,IList<int>> selection = preprocessingData. GetSelection();142 IDictionary<int,IList<int>> selection = preprocessingData.Selection; 143 143 int variableIndex = preprocessingData.GetColumnIndex(variableName); 144 144 -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/CorrelationMatrixContent.cs
r10962 r10978 26 26 27 27 namespace HeuristicLab.DataPreprocessing { 28 29 28 [Item("Feature Correlation Matrix", "Represents the feature correlation matrix.")] 30 29 public class CorrelationMatrixContent : Item, IViewChartShortcut { 30 public static new Image StaticItemImage { 31 get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; } 32 } 33 34 private IPreprocessingContext Context { get; set; } 35 private ITransactionalPreprocessingData PreprocessingData { 36 get { return Context.Data; } 37 } 31 38 32 39 public DataAnalysisProblemData ProblemData { … … 34 41 var creator = new ProblemDataCreator(Context); 35 42 return (DataAnalysisProblemData)creator.CreateProblemData(); 36 } 43 } 37 44 } 38 45 39 public ITransactionalPreprocessingData PreprocessingData {40 get {41 return Context.Data;42 }43 }44 45 private IPreprocessingContext Context { get; set; }46 46 public CorrelationMatrixContent(IPreprocessingContext context) { 47 47 Context = context; 48 49 50 48 } 51 49 52 50 public CorrelationMatrixContent(CorrelationMatrixContent original, Cloner cloner) 53 51 : base(original, cloner) { 54 55 52 } 56 57 public static new Image StaticItemImage {58 get { return HeuristicLab.Common.Resources.VSImageLibrary.Gradient; }59 }60 61 53 public override IDeepCloneable Clone(Cloner cloner) { 62 54 return new CorrelationMatrixContent(this, cloner); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/DataGridLogic.cs
r10900 r10978 144 144 145 145 146 147 146 public void SetSelection(IDictionary<int, IList<int>> selection) { 148 preprocessingData.Se tSelection(selection);147 preprocessingData.Selection = selection; 149 148 } 150 149 151 150 public IDictionary<int, IList<int>> GetSelection() { 152 return preprocessingData. GetSelection();151 return preprocessingData.Selection; 153 152 } 154 153 public void ClearSelection() { -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/FilteredPreprocessingData.cs
r10939 r10978 10 10 namespace HeuristicLab.DataPreprocessing.Implementations { 11 11 public class FilteredPreprocessingData : NamedItem, IFilteredPreprocessingData { 12 protected ITransactionalPreprocessingData originalData; 13 protected ITransactionalPreprocessingData filteredData; 12 private readonly ITransactionalPreprocessingData originalData; 13 private ITransactionalPreprocessingData filteredData; 14 15 public IDictionary<int, IList<int>> Selection { 16 get { return originalData.Selection; } 17 set { originalData.Selection = value; } 18 } 14 19 15 20 protected FilteredPreprocessingData(FilteredPreprocessingData original, Cloner cloner) 16 21 : base(original, cloner) { 17 originalData = (ITransactionalPreprocessingData)original.originalData;18 filteredData = (ITransactionalPreprocessingData)original.filteredData;22 originalData = original.originalData; 23 filteredData = original.filteredData; 19 24 } 20 25 … … 34 39 35 40 public void SetCell<T>(int columnIndex, int rowIndex, T value) { 36 ReadOnlyOnFilterData.SetCell<T>(columnIndex, rowIndex, value); 41 if (IsFiltered) 42 throw new InvalidOperationException("SetCell not possible while data is filtered"); 43 44 originalData.SetCell<T>(columnIndex, rowIndex, value); 37 45 } 38 46 … … 50 58 51 59 public void SetValues<T>(int columnIndex, IList<T> values) { 52 ReadOnlyOnFilterData.SetValues<T>(columnIndex, values); 60 if (IsFiltered) 61 throw new InvalidOperationException("SetValues not possible while data is filtered"); 62 63 originalData.SetValues<T>(columnIndex, values); 53 64 } 54 65 55 66 public void InsertRow(int rowIndex) { 56 ReadOnlyOnFilterData.InsertRow(rowIndex); 67 if (IsFiltered) 68 throw new InvalidOperationException("InsertRow not possible while data is filtered"); 69 70 originalData.InsertRow(rowIndex); 57 71 } 58 72 59 73 public void DeleteRow(int rowIndex) { 60 ReadOnlyOnFilterData.DeleteRow(rowIndex); 74 if (IsFiltered) 75 throw new InvalidOperationException("DeleteRow not possible while data is filtered"); 76 77 originalData.DeleteRow(rowIndex); 61 78 } 62 79 63 80 public void InsertColumn<T>(string variableName, int columnIndex) { 64 ReadOnlyOnFilterData.InsertColumn<T>(variableName, columnIndex); 81 if (IsFiltered) 82 throw new InvalidOperationException("InsertColumn not possible while data is filtered"); 83 84 originalData.InsertColumn<T>(variableName, columnIndex); 65 85 } 66 86 67 87 public void DeleteColumn(int columnIndex) { 68 ReadOnlyOnFilterData.DeleteColumn(columnIndex); 88 if (IsFiltered) 89 throw new InvalidOperationException("DeleteColumn not possible while data is filtered"); 90 originalData.DeleteColumn(columnIndex); 69 91 } 70 92 … … 153 175 } 154 176 155 public ITransactionalPreprocessingData ReadOnlyOnFilterData { 156 get { 157 if (IsFiltered) 158 throw new InvalidOperationException(); 159 160 return originalData; 161 } 162 } 177 178 public bool IsUndoAvailable { 179 get { return IsFiltered ? false : originalData.IsUndoAvailable; } 180 } 181 163 182 164 183 public bool IsFiltered { … … 171 190 } 172 191 173 public bool IsUndoAvailable {174 get { return IsFiltered ? false : originalData.IsUndoAvailable; }175 }176 192 177 193 public void Undo() { 178 ReadOnlyOnFilterData.Undo(); 194 if (IsFiltered) 195 throw new InvalidOperationException("Undo not possible while data is filtered"); 196 197 originalData.Undo(); 179 198 } 180 199 181 200 public void InTransaction(Action action, DataPreprocessingChangedEventType type = DataPreprocessingChangedEventType.Any) { 182 ReadOnlyOnFilterData.InTransaction(action, type); 201 if (IsFiltered) 202 throw new InvalidOperationException("Transaction not possible while data is filtered"); 203 originalData.InTransaction(action, type); 183 204 } 184 205 185 206 public void BeginTransaction(DataPreprocessingChangedEventType type) { 186 ReadOnlyOnFilterData.BeginTransaction(type); 207 if (IsFiltered) 208 throw new InvalidOperationException("Transaction not possible while data is filtered"); 209 originalData.BeginTransaction(type); 187 210 } 188 211 … … 194 217 195 218 #region IPreprocessingData Members 196 197 198 public void SetSelection(IDictionary<int, IList<int>> selection) {199 originalData.SetSelection(selection);200 }201 202 public IDictionary<int, IList<int>> GetSelection() {203 return originalData.GetSelection();204 }205 219 206 220 public void ClearSelection() { -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingContext.cs
r10786 r10978 34 34 35 35 public IFilteredPreprocessingData Data { get; private set; } 36 37 public IDataAnalysisProblemData DataAnalysisProblemData { get; private set; }38 39 36 public IAlgorithm Algorithm { get; private set; } 40 41 37 public IDataAnalysisProblem Problem { get; private set; } 42 38 43 39 public PreprocessingContext(IDataAnalysisProblemData dataAnalysisProblemData, IAlgorithm algorithm, IDataAnalysisProblem problem) { 44 45 40 TransactionalPreprocessingData transactionalPreprocessingData = new TransactionalPreprocessingData(dataAnalysisProblemData); 46 41 47 42 Data = new FilteredPreprocessingData(transactionalPreprocessingData); 48 DataAnalysisProblemData = dataAnalysisProblemData;49 43 Algorithm = algorithm; 50 44 Problem = problem; … … 54 48 : base(original, cloner) { 55 49 Data = cloner.Clone(original.Data); 56 DataAnalysisProblemData = original.DataAnalysisProblemData;57 50 Algorithm = original.Algorithm; 58 51 Problem = original.Problem; -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/PreprocessingData.cs
r10842 r10978 33 33 34 34 [Item("PreprocessingData", "Represents data used for preprocessing.")] 35 public class PreprocessingData : NamedItem, IPreprocessingData { 35 public abstract class PreprocessingData : NamedItem, IPreprocessingData { 36 37 protected double trainingToTestRatio; 38 public IntRange TrainingPartition { 39 get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); } 40 } 41 public IntRange TestPartition { 42 get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); } 43 } 44 45 protected IList<ITransformation> transformations; 46 public IList<ITransformation> Transformations { 47 get { return transformations; } 48 } 36 49 37 50 protected IList<IList> variableValues; 38 39 51 protected IList<string> variableNames; 40 52 41 protected double trainingToTestRatio; 42 43 protected IList<ITransformation> transformations; 44 45 protected IDictionary<int, IList<int>> currentSelection; 53 public IEnumerable<string> VariableNames { 54 get { return variableNames; } 55 } 56 57 public int Columns { 58 get { return variableNames.Count; } 59 } 60 61 public int Rows { 62 get { return variableValues.Count > 0 ? variableValues[0].Count : 0; } 63 } 64 65 protected IDictionary<int, IList<int>> selection; 66 public IDictionary<int, IList<int>> Selection { 67 get { return selection; } 68 set { 69 selection = value; 70 OnSelectionChanged(); 71 } 72 } 46 73 47 74 protected PreprocessingData(PreprocessingData original, Cloner cloner) … … 53 80 } 54 81 55 p ublicPreprocessingData(IDataAnalysisProblemData problemData)82 protected PreprocessingData(IDataAnalysisProblemData problemData) 56 83 : base() { 57 84 Name = "Preprocessing Data"; 58 85 59 86 transformations = new List<ITransformation>(); 60 currentSelection = new Dictionary<int, IList<int>>();87 selection = new Dictionary<int, IList<int>>(); 61 88 62 89 variableNames = new List<string>(problemData.Dataset.VariableNames); 63 // create dictionary from variable name to index64 90 65 91 int columnIndex = 0; … … 73 99 variableValues.Insert(columnIndex, CreateColumn<DateTime>(problemData.Dataset, columnIndex, x => DateTime.Parse(x))); 74 100 } else { 75 throw new ArgumentException("The datatype of column " + variableName + " must be of type List<double>, List<string> or List<DateTime>");101 throw new ArgumentException("The datatype of column " + variableName + " must be of type double, string or DateTime"); 76 102 } 77 103 ++columnIndex; … … 97 123 } 98 124 99 #region NamedItem abstract Member Implementations100 101 public override IDeepCloneable Clone(Cloner cloner) {102 return new PreprocessingData(this, cloner);103 }104 105 #endregion106 125 107 126 #region IPreprocessingData Members … … 111 130 } 112 131 113 114 132 public virtual void SetCell<T>(int columnIndex, int rowIndex, T value) { 115 133 variableValues[columnIndex][rowIndex] = value; 116 134 } 117 135 118 119 136 public string GetCellAsString(int columnIndex, int rowIndex) { 120 137 return variableValues[columnIndex][rowIndex].ToString(); 121 138 } 122 139 140 public string GetVariableName(int columnIndex) { 141 return variableNames[columnIndex]; 142 } 143 144 public int GetColumnIndex(string variableName) { 145 return variableNames.IndexOf(variableName); 146 } 147 148 public bool IsType<T>(int columnIndex) { 149 return variableValues[columnIndex] is List<T>; 150 } 123 151 124 152 [Obsolete("use the index based variant, is faster")] … … 130 158 if (considerSelection) { 131 159 var list = new List<T>(); 132 foreach (var rowIdx in currentSelection[columnIndex]) {160 foreach (var rowIdx in selection[columnIndex]) { 133 161 list.Add((T)variableValues[columnIndex][rowIdx]); 134 162 } … … 170 198 } 171 199 172 public IntRange TrainingPartition {173 get { return new IntRange(0, (int)(Rows * trainingToTestRatio)); }174 }175 176 public IntRange TestPartition {177 get { return new IntRange((int)(Rows * trainingToTestRatio), Rows); }178 }179 180 public IList<ITransformation> Transformations {181 get { return transformations; }182 }183 184 public string GetVariableName(int columnIndex) {185 return variableNames[columnIndex];186 }187 188 public IEnumerable<string> VariableNames {189 get { return variableNames; }190 }191 192 public int GetColumnIndex(string variableName) {193 return variableNames.IndexOf(variableName);194 }195 196 public bool IsType<T>(int columnIndex) {197 return variableValues[columnIndex] is List<T>;198 }199 200 public int Columns {201 get { return variableNames.Count; }202 }203 204 public int Rows {205 get { return variableValues.Count > 0 ? variableValues[0].Count : 0; }206 }207 208 200 public Dataset ExportToDataset() { 209 201 IList<IList> values = new List<IList>(); … … 217 209 } 218 210 219 public void SetSelection(IDictionary<int, IList<int>> selection) {220 currentSelection = selection;221 if (SelectionChanged != null) {222 SelectionChanged(this, new EventArgs());223 }224 }225 226 public IDictionary<int, IList<int>> GetSelection() {227 return currentSelection;228 }229 230 211 public void ClearSelection() { 231 currentSelection = new Dictionary<int, IList<int>>();212 Selection = new Dictionary<int, IList<int>>(); 232 213 } 233 214 234 215 public event EventHandler SelectionChanged; 235 216 protected virtual void OnSelectionChanged() { 217 var listeners = SelectionChanged; 218 if (listeners != null) listeners(this, EventArgs.Empty); 219 } 220 221 public event DataPreprocessingChangedEventHandler Changed; 222 protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) { 223 var listeners = Changed; 224 if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row)); 225 } 236 226 #endregion 237 227 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/SearchLogic.cs
r10817 r10978 114 114 { 115 115 if (considerSelection) { 116 var selectedRows = preprocessingData. GetSelection()[columnIndex];116 var selectedRows = preprocessingData.Selection[columnIndex]; 117 117 118 118 List<T> values = new List<T>(); -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/TransactionalPreprocessingData.cs
r10814 r10978 30 30 namespace HeuristicLab.DataPreprocessing { 31 31 32 internal class Snapshot {33 public IList<IList> VariableValues { get; set; }34 35 public IList<string> VariableNames { get; set; }36 37 public double TrainingToTestRatio { get; set; }38 39 public IList<ITransformation> Transformations { get; set; }40 41 public DataPreprocessingChangedEventType ChangedType { get; set; }42 43 public int ChangedColumn { get; set; }44 45 public int ChangedRow { get; set; }46 }47 48 32 [Item("PreprocessingData", "Represents data used for preprocessing.")] 49 33 public class TransactionalPreprocessingData : PreprocessingData, ITransactionalPreprocessingData { 50 34 35 private class Snapshot { 36 public IList<IList> VariableValues { get; set; } 37 public IList<string> VariableNames { get; set; } 38 39 public double TrainingToTestRatio { get; set; } 40 public IList<ITransformation> Transformations { get; set; } 41 public DataPreprocessingChangedEventType ChangedType { get; set; } 42 43 public int ChangedColumn { get; set; } 44 public int ChangedRow { get; set; } 45 } 46 51 47 private const int MAX_UNDO_DEPTH = 5; 52 48 53 private IList<Snapshot> undoHistory; 54 55 private Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>(); 56 57 private DataPreprocessingChangedEventType lastOccuredChangedType = DataPreprocessingChangedEventType.Any; 49 private readonly IList<Snapshot> undoHistory = new List<Snapshot>(); 50 private readonly Stack<DataPreprocessingChangedEventType> eventStack = new Stack<DataPreprocessingChangedEventType>(); 58 51 59 52 public bool IsInTransaction { get { return eventStack.Count > 0; } } … … 61 54 public TransactionalPreprocessingData(IDataAnalysisProblemData problemData) 62 55 : base(problemData) { 63 undoHistory = new List<Snapshot>();64 56 } 65 57 66 58 private TransactionalPreprocessingData(TransactionalPreprocessingData original, Cloner cloner) 67 59 : base(original, cloner) { 68 undoHistory = new List<Snapshot>(); 69 } 60 } 70 61 71 62 private void SaveSnapshot(DataPreprocessingChangedEventType changedType, int column, int row) { 72 if ( eventStack.Count > 0) return;63 if (IsInTransaction) return; 73 64 74 65 var currentSnapshot = new Snapshot { … … 144 135 #region TransactionalPreprocessingData members 145 136 146 public event DataPreprocessingChangedEventHandler Changed;147 protected virtual void OnChanged(DataPreprocessingChangedEventType type, int column, int row) {148 var listeners = Changed;149 if (listeners != null) listeners(this, new DataPreprocessingChangedEventArgs(type, column, row));150 }151 152 137 public bool IsUndoAvailable { 153 138 get { return undoHistory.Count > 0; } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingContext.cs
r10783 r10978 27 27 28 28 namespace HeuristicLab.DataPreprocessing { 29 public interface IPreprocessingContext 30 : IItem { 29 public interface IPreprocessingContext : IItem { 31 30 32 31 IFilteredPreprocessingData Data { get; } 33 34 [Obsolete]35 IDataAnalysisProblemData DataAnalysisProblemData { get; }36 37 32 IAlgorithm Algorithm { get; } 38 39 33 IDataAnalysisProblem Problem { get; } 40 34 41 35 IItem ExportAlgorithmOrProblem(); 42 43 36 IAlgorithm ExportAlgorithm(); 44 45 37 IProblem ExportProblem(); 46 38 } -
branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Interfaces/IPreprocessingData.cs
r10811 r10978 65 65 Dataset ExportToDataset(); 66 66 67 void SetSelection(IDictionary<int, IList<int>> selection); 68 IDictionary<int, IList<int>> GetSelection(); 67 IDictionary<int, IList<int>> Selection { get; set; } 69 68 void ClearSelection(); 70 69
Note: See TracChangeset
for help on using the changeset viewer.