Changeset 15926 for branches/2913_MatlabScriptProblemInstanceProvider
- Timestamp:
- 05/02/18 13:14:16 (7 years ago)
- Location:
- branches/2913_MatlabScriptProblemInstanceProvider
- Files:
-
- 5 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/HeuristicLab.Problems.Instances.DataAnalysis.Views-3.3.csproj ¶
r15912 r15926 123 123 <DependentUpon>RegressionImportDialog.cs</DependentUpon> 124 124 </Compile> 125 <Compile Include="Regression\Matlab\IMLVariablesLoader.cs"> 126 <SubType>Form</SubType> 127 </Compile> 128 <Compile Include="Regression\Matlab\MLDoubleArrayLoader.cs"> 129 <SubType>Form</SubType> 130 </Compile> 131 <Compile Include="Regression\Matlab\MLTimeseriesLoader.cs"> 132 <SubType>Form</SubType> 133 </Compile> 134 <Compile Include="Regression\Matlab\MLVariablesLoader.cs"> 135 <SubType>Form</SubType> 136 </Compile> 125 137 <Compile Include="Regression\Matlab\RegressionMatlabImportDialog.cs"> 126 138 <SubType>Form</SubType> -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/Regression/Matlab/RegressionMatlabImportDialog.Designer.cs ¶
r15919 r15926 32 32 this.ToolTip = new System.Windows.Forms.ToolTip(this.components); 33 33 this.ProblemDataSettingsGroupBox = new System.Windows.Forms.GroupBox(); 34 this.ErrorTextBox = new System.Windows.Forms.TextBox(); 35 this.label1 = new System.Windows.Forms.Label(); 34 36 this.TargetVariableComboBox = new System.Windows.Forms.ComboBox(); 35 this.ErrorTextBox = new System.Windows.Forms.TextBox();36 37 this.PreviewLabel = new System.Windows.Forms.Label(); 37 38 this.TestLabel = new System.Windows.Forms.Label(); … … 42 43 this.OkButton = new System.Windows.Forms.Button(); 43 44 this.MatlabVariablesGroupBox = new System.Windows.Forms.GroupBox(); 45 this.DatatypeSelectorTabControl = new System.Windows.Forms.TabControl(); 46 this.Timeseries = new System.Windows.Forms.TabPage(); 47 this.TimeseriesListBox = new System.Windows.Forms.CheckedListBox(); 48 this.DoubleArrays = new System.Windows.Forms.TabPage(); 49 this.DoubleArraysListBox = new System.Windows.Forms.CheckedListBox(); 44 50 this.LoadValuesButton = new System.Windows.Forms.Button(); 45 this.VariablesListBox = new System.Windows.Forms.CheckedListBox();46 this.label1 = new System.Windows.Forms.Label();47 51 this.StatusLabel = new System.Windows.Forms.Label(); 48 52 this.ProblemDataSettingsGroupBox.SuspendLayout(); 49 53 ((System.ComponentModel.ISupportInitialize)(this.TrainingTestTrackBar)).BeginInit(); 50 54 this.MatlabVariablesGroupBox.SuspendLayout(); 55 this.DatatypeSelectorTabControl.SuspendLayout(); 56 this.Timeseries.SuspendLayout(); 57 this.DoubleArrays.SuspendLayout(); 51 58 this.SuspendLayout(); 52 59 // … … 97 104 this.ProblemDataSettingsGroupBox.Controls.Add(this.TrainingLabel); 98 105 this.ProblemDataSettingsGroupBox.Controls.Add(this.TrainingTestTrackBar); 99 this.ProblemDataSettingsGroupBox.Location = new System.Drawing.Point(12, 191);106 this.ProblemDataSettingsGroupBox.Location = new System.Drawing.Point(12, 210); 100 107 this.ProblemDataSettingsGroupBox.Name = "ProblemDataSettingsGroupBox"; 101 this.ProblemDataSettingsGroupBox.Size = new System.Drawing.Size(447, 2 25);108 this.ProblemDataSettingsGroupBox.Size = new System.Drawing.Size(447, 258); 102 109 this.ProblemDataSettingsGroupBox.TabIndex = 20; 103 110 this.ProblemDataSettingsGroupBox.TabStop = false; 104 111 this.ProblemDataSettingsGroupBox.Text = "ProblemData Settings"; 105 112 // 106 // TargetVariableComboBox107 //108 this.TargetVariableComboBox.BackColor = System.Drawing.SystemColors.Control;109 this.TargetVariableComboBox.FormattingEnabled = true;110 this.TargetVariableComboBox.Location = new System.Drawing.Point(256, 19);111 this.TargetVariableComboBox.Name = "TargetVariableComboBox";112 this.TargetVariableComboBox.Size = new System.Drawing.Size(185, 21);113 this.TargetVariableComboBox.TabIndex = 8;114 //115 113 // ErrorTextBox 116 114 // 117 this.ErrorTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 115 this.ErrorTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 116 | System.Windows.Forms.AnchorStyles.Left) 118 117 | System.Windows.Forms.AnchorStyles.Right))); 119 118 this.ErrorTextBox.Location = new System.Drawing.Point(6, 15); … … 121 120 this.ErrorTextBox.Name = "ErrorTextBox"; 122 121 this.ErrorTextBox.ReadOnly = true; 123 this.ErrorTextBox.Size = new System.Drawing.Size(435, 2 04);122 this.ErrorTextBox.Size = new System.Drawing.Size(435, 237); 124 123 this.ErrorTextBox.TabIndex = 0; 125 124 this.ErrorTextBox.Text = "Open a Matlab File"; 125 // 126 // label1 127 // 128 this.label1.AutoSize = true; 129 this.label1.Location = new System.Drawing.Point(9, 22); 130 this.label1.Name = "label1"; 131 this.label1.Size = new System.Drawing.Size(82, 13); 132 this.label1.TabIndex = 9; 133 this.label1.Text = "Target Variable:"; 134 // 135 // TargetVariableComboBox 136 // 137 this.TargetVariableComboBox.BackColor = System.Drawing.SystemColors.Control; 138 this.TargetVariableComboBox.FormattingEnabled = true; 139 this.TargetVariableComboBox.Location = new System.Drawing.Point(97, 19); 140 this.TargetVariableComboBox.Name = "TargetVariableComboBox"; 141 this.TargetVariableComboBox.Size = new System.Drawing.Size(185, 21); 142 this.TargetVariableComboBox.TabIndex = 8; 126 143 // 127 144 // PreviewLabel … … 156 173 this.PreviewDatasetMatrix.ShowRowsAndColumnsTextBox = false; 157 174 this.PreviewDatasetMatrix.ShowStatisticalInformation = false; 158 this.PreviewDatasetMatrix.Size = new System.Drawing.Size(435, 1 11);175 this.PreviewDatasetMatrix.Size = new System.Drawing.Size(435, 144); 159 176 this.PreviewDatasetMatrix.TabIndex = 0; 160 177 // … … 185 202 this.CancellationButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 186 203 this.CancellationButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; 187 this.CancellationButton.Location = new System.Drawing.Point(384, 4 22);204 this.CancellationButton.Location = new System.Drawing.Point(384, 474); 188 205 this.CancellationButton.Name = "CancellationButton"; 189 206 this.CancellationButton.Size = new System.Drawing.Size(75, 23); … … 197 214 this.OkButton.DialogResult = System.Windows.Forms.DialogResult.OK; 198 215 this.OkButton.Enabled = false; 199 this.OkButton.Location = new System.Drawing.Point(303, 4 22);216 this.OkButton.Location = new System.Drawing.Point(303, 474); 200 217 this.OkButton.Name = "OkButton"; 201 218 this.OkButton.Size = new System.Drawing.Size(75, 23); … … 206 223 // MatlabVariablesGroupBox 207 224 // 225 this.MatlabVariablesGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 226 | System.Windows.Forms.AnchorStyles.Right))); 227 this.MatlabVariablesGroupBox.Controls.Add(this.DatatypeSelectorTabControl); 208 228 this.MatlabVariablesGroupBox.Controls.Add(this.LoadValuesButton); 209 this.MatlabVariablesGroupBox.Controls.Add(this.VariablesListBox);210 229 this.MatlabVariablesGroupBox.Location = new System.Drawing.Point(12, 32); 211 230 this.MatlabVariablesGroupBox.Name = "MatlabVariablesGroupBox"; 212 this.MatlabVariablesGroupBox.Size = new System.Drawing.Size(447, 1 53);231 this.MatlabVariablesGroupBox.Size = new System.Drawing.Size(447, 172); 213 232 this.MatlabVariablesGroupBox.TabIndex = 22; 214 233 this.MatlabVariablesGroupBox.TabStop = false; 215 234 this.MatlabVariablesGroupBox.Text = "Matlab variables"; 216 235 // 236 // DatatypeSelectorTabControl 237 // 238 this.DatatypeSelectorTabControl.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 239 | System.Windows.Forms.AnchorStyles.Right))); 240 this.DatatypeSelectorTabControl.Controls.Add(this.Timeseries); 241 this.DatatypeSelectorTabControl.Controls.Add(this.DoubleArrays); 242 this.DatatypeSelectorTabControl.Location = new System.Drawing.Point(6, 19); 243 this.DatatypeSelectorTabControl.Name = "DatatypeSelectorTabControl"; 244 this.DatatypeSelectorTabControl.SelectedIndex = 0; 245 this.DatatypeSelectorTabControl.Size = new System.Drawing.Size(435, 124); 246 this.DatatypeSelectorTabControl.TabIndex = 24; 247 // 248 // Timeseries 249 // 250 this.Timeseries.Controls.Add(this.TimeseriesListBox); 251 this.Timeseries.Location = new System.Drawing.Point(4, 22); 252 this.Timeseries.Name = "Timeseries"; 253 this.Timeseries.Padding = new System.Windows.Forms.Padding(3); 254 this.Timeseries.Size = new System.Drawing.Size(427, 98); 255 this.Timeseries.TabIndex = 0; 256 this.Timeseries.Text = "Timeseries"; 257 this.Timeseries.UseVisualStyleBackColor = true; 258 // 259 // TimeseriesListBox 260 // 261 this.TimeseriesListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 262 | System.Windows.Forms.AnchorStyles.Right))); 263 this.TimeseriesListBox.FormattingEnabled = true; 264 this.TimeseriesListBox.Location = new System.Drawing.Point(0, 2); 265 this.TimeseriesListBox.Name = "TimeseriesListBox"; 266 this.TimeseriesListBox.Size = new System.Drawing.Size(424, 94); 267 this.TimeseriesListBox.TabIndex = 23; 268 // 269 // DoubleArrays 270 // 271 this.DoubleArrays.Controls.Add(this.DoubleArraysListBox); 272 this.DoubleArrays.Location = new System.Drawing.Point(4, 22); 273 this.DoubleArrays.Name = "DoubleArrays"; 274 this.DoubleArrays.Padding = new System.Windows.Forms.Padding(3); 275 this.DoubleArrays.Size = new System.Drawing.Size(427, 98); 276 this.DoubleArrays.TabIndex = 1; 277 this.DoubleArrays.Text = "Double Arrays"; 278 this.DoubleArrays.UseVisualStyleBackColor = true; 279 // 280 // DoubleArraysListBox 281 // 282 this.DoubleArraysListBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 283 | System.Windows.Forms.AnchorStyles.Right))); 284 this.DoubleArraysListBox.FormattingEnabled = true; 285 this.DoubleArraysListBox.Location = new System.Drawing.Point(0, 4); 286 this.DoubleArraysListBox.Name = "DoubleArraysListBox"; 287 this.DoubleArraysListBox.Size = new System.Drawing.Size(425, 94); 288 this.DoubleArraysListBox.TabIndex = 24; 289 // 217 290 // LoadValuesButton 218 291 // 219 292 this.LoadValuesButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 220 293 this.LoadValuesButton.Enabled = false; 221 this.LoadValuesButton.Location = new System.Drawing.Point(366, 1 24);294 this.LoadValuesButton.Location = new System.Drawing.Point(366, 143); 222 295 this.LoadValuesButton.Name = "LoadValuesButton"; 223 296 this.LoadValuesButton.Size = new System.Drawing.Size(75, 23); … … 226 299 this.LoadValuesButton.UseVisualStyleBackColor = true; 227 300 // 228 // VariablesListBox229 //230 this.VariablesListBox.FormattingEnabled = true;231 this.VariablesListBox.Location = new System.Drawing.Point(6, 18);232 this.VariablesListBox.Name = "VariablesListBox";233 this.VariablesListBox.Size = new System.Drawing.Size(435, 94);234 this.VariablesListBox.TabIndex = 22;235 //236 // label1237 //238 this.label1.AutoSize = true;239 this.label1.Location = new System.Drawing.Point(168, 22);240 this.label1.Name = "label1";241 this.label1.Size = new System.Drawing.Size(82, 13);242 this.label1.TabIndex = 9;243 this.label1.Text = "Target Variable:";244 //245 301 // StatusLabel 246 302 // 247 303 this.StatusLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 248 304 this.StatusLabel.AutoSize = true; 249 this.StatusLabel.Location = new System.Drawing.Point(9, 4 27);305 this.StatusLabel.Location = new System.Drawing.Point(9, 479); 250 306 this.StatusLabel.Name = "StatusLabel"; 251 307 this.StatusLabel.Size = new System.Drawing.Size(37, 13); … … 257 313 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 258 314 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 259 this.ClientSize = new System.Drawing.Size(471, 457);315 this.ClientSize = new System.Drawing.Size(471, 509); 260 316 this.Controls.Add(this.StatusLabel); 261 317 this.Controls.Add(this.MatlabVariablesGroupBox); … … 273 329 ((System.ComponentModel.ISupportInitialize)(this.TrainingTestTrackBar)).EndInit(); 274 330 this.MatlabVariablesGroupBox.ResumeLayout(false); 331 this.DatatypeSelectorTabControl.ResumeLayout(false); 332 this.Timeseries.ResumeLayout(false); 333 this.DoubleArrays.ResumeLayout(false); 275 334 this.ResumeLayout(false); 276 335 this.PerformLayout(); … … 296 355 private System.Windows.Forms.GroupBox MatlabVariablesGroupBox; 297 356 protected System.Windows.Forms.Button LoadValuesButton; 298 private System.Windows.Forms.CheckedListBox VariablesListBox;299 357 private System.Windows.Forms.ComboBox TargetVariableComboBox; 300 358 protected System.Windows.Forms.Label label1; 301 359 protected System.Windows.Forms.Label StatusLabel; 360 private System.Windows.Forms.TabControl DatatypeSelectorTabControl; 361 private System.Windows.Forms.TabPage Timeseries; 362 private System.Windows.Forms.CheckedListBox TimeseriesListBox; 363 private System.Windows.Forms.TabPage DoubleArrays; 364 private System.Windows.Forms.CheckedListBox DoubleArraysListBox; 302 365 } 303 366 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis.Views/3.3/Regression/Matlab/RegressionMatlabImportDialog.cs ¶
r15919 r15926 19 19 namespace HeuristicLab.Problems.Instances.DataAnalysis.Views.Regression.Matlab { 20 20 public partial class RegressionMatlabImportDialog : Form { 21 private const int TAB_INDEX_TIMESERIES = 0; 22 private const int TAB_INDEX_DOUBLE_ARRAYS = 1; 23 21 24 private IMatlabConnector _mlConnector; 25 26 private IMLVariablesLoader _variablesLoader; 27 private IMLVariablesLoader _timeseriesLoader; 28 private IMLVariablesLoader _doubleArraysLoader; 29 30 private CancellationTokenSource _cts = new CancellationTokenSource(); 31 22 32 public event EventHandler<EventArgs<string>> StatusChangedEvent; 23 33 public event EventHandler<EventArgs<string>> ErrorOccuredEvent; 24 25 26 34 27 35 /// <summary> … … 49 57 } 50 58 51 private IList<KeyValuePair<string, MLDatatype>> _selectedVariables; 52 53 public IEnumerable<KeyValuePair<string, MLDatatype>> SelectedVariables { 59 private IList<MLVariableInfo> _selectedTimeseries; 60 private IList<MLVariableInfo> _selectedDoubleArrays; 61 62 public IEnumerable<MLVariableInfo> SelectedVariables { 54 63 get { 55 return _ selectedVariables;64 return _variablesLoader.SelectedVariables; 56 65 } 57 66 } … … 60 69 InitializeComponent(); 61 70 62 _selectedVariables = new List<KeyValuePair<string, MLDatatype>>(); 71 _selectedTimeseries = new List<MLVariableInfo>(); 72 _selectedDoubleArrays = new List<MLVariableInfo>(); 63 73 _values = new Dataset(); 64 74 65 75 this.FormClosed += (s, e) => DisposeMatlabConnector(); 66 76 OpenFileButton.Click += OpenFileButtonClick; 67 VariablesListBox.ItemCheck += (s, e) => BeginInvoke((MethodInvoker)(() => CheckedItemsChanged(s, e))); 77 78 DatatypeSelectorTabControl.SelectedIndexChanged += (s, e) => BeginInvoke((MethodInvoker)(() => DatatypeSelectorTabControlTabIndexChanged(s, e))); 79 68 80 LoadValuesButton.Click += LoadValuesButtonClick; 69 81 TrainingTestTrackBar.ValueChanged += TrainingTestTrackBarValueChanged; 82 70 83 StatusChangedEvent += (s, e) => BeginInvoke((MethodInvoker)(() => StatusLabel.Text = e.Value)); 71 84 ErrorOccuredEvent += (s, e) => BeginInvoke((MethodInvoker)(() => { … … 74 87 ErrorTextBox.Visible = true; 75 88 })); 76 } 77 78 private void CheckedItemsChanged(object sender, ItemCheckEventArgs e) { 79 _selectedVariables.Clear(); 80 foreach (KeyValuePair<string, MLDatatype> item in VariablesListBox.CheckedItems) { 81 if (item.Value == MLDatatype.Timeseries) { 82 _selectedVariables.Add(item); 83 } 84 } 85 LoadValuesButton.Enabled = VariablesListBox.CheckedIndices.Count > 0; 86 } 87 88 #region Events 89 89 90 _timeseriesLoader = new MLTimeseriesLoader(this, TimeseriesListBox); 91 _timeseriesLoader.NumberOfSelectedVariablesChanged += NumberOfSelectedVariablesChanged; 92 _doubleArraysLoader = new MLDoubleArrayLoader(this, DoubleArraysListBox); 93 _doubleArraysLoader.NumberOfSelectedVariablesChanged += NumberOfSelectedVariablesChanged; 94 95 _variablesLoader = _timeseriesLoader; 96 97 } 98 99 #region Methods for Events 100 101 private void NumberOfSelectedVariablesChanged(object s, EventArgs<int> e) { 102 LoadValuesButton.Enabled = e.Value > 0; 103 } 104 105 private void DatatypeSelectorTabControlTabIndexChanged(object s, EventArgs e) { 106 switch (DatatypeSelectorTabControl.SelectedIndex) { 107 case TAB_INDEX_TIMESERIES: 108 _variablesLoader = _timeseriesLoader; 109 break; 110 case TAB_INDEX_DOUBLE_ARRAYS: 111 _variablesLoader = _doubleArraysLoader; 112 break; 113 } 114 115 LoadValuesButton.Enabled = _variablesLoader.SelectedVariables.Count() > 0; 116 } 90 117 91 118 private void LoadValuesButtonClick(object sender, EventArgs e) { 119 _cts.Cancel(); 120 _cts = new CancellationTokenSource(); 92 121 LoadValuesAsync(); 93 122 } … … 106 135 } 107 136 #endregion 108 137 109 138 /// <summary> 110 139 /// Fires the ErrorOccuredEvent with the given text message. … … 127 156 if (_mlConnector == null) { 128 157 _mlConnector = MatlabApiFactory.CreateMatlabConnector(); 158 _mlConnector.ErrorOccuredEvent += ErrorOccured; 129 159 } 130 160 } … … 141 171 142 172 143 144 173 /// <summary> 145 174 /// This method reads all available variables form the selected matlab scirpt and puts them into the list view. … … 147 176 private async void GetVariableNamesAsync() { 148 177 UpdateStatus("Opening Matlab"); 149 150 178 var path = openFileDialog.FileName; 151 179 ProblemTextBox.Text = path; … … 156 184 157 185 UpdateStatus("Loading variable names"); 158 var variablesListBoxItems = VariablesListBox.Items; 159 variablesListBoxItems.Clear(); 160 foreach (var item in variables) { 161 variablesListBoxItems.Add(item, false); 162 } 186 _timeseriesLoader.DisplayVariables(variables); 187 _doubleArraysLoader.DisplayVariables(variables); 163 188 UpdateStatus("Done"); 164 189 } 165 190 166 /// <summary>167 /// Loads the values of the selected timeseries values and displays them at the preview control.168 /// </summary>169 191 private async void LoadValuesAsync() { 192 UpdateStatus("Loading values from Matlab"); 170 193 try { 171 PreviewDatasetMatrix.Content = new Dataset(); 172 173 UpdateStatus("Loading values from Matlab"); 174 var vals = await Task.Run<List<MLTimeseries>>(() => { 175 var values = new List<MLTimeseries>(); 176 foreach (KeyValuePair<string, MLDatatype> item in VariablesListBox.CheckedItems) { 177 if (item.Value == MLDatatype.Timeseries) { 178 var val = _mlConnector.GetTimeseries(item.Key); 179 if (val != null) { 180 values.Add(val); 181 } 182 } 183 } 184 return values; 185 }); 186 187 UpdateStatus("Converting values"); 188 DisplayLoadedValuesAsync(await Task.Run<MLTimeseries>(() => new MLTimeseries(vals))); 189 ErrorTextBox.Text = String.Empty; 190 ErrorTextBox.Visible = false; 191 OkButton.Enabled = true; 194 // As there can be a huge amount of data, it should be freed before reallocating it. 195 OkButton.Enabled = false; 196 _values = new Dataset(); 197 PreviewDatasetMatrix.Content = _values; 198 TargetVariableComboBox.DataSource = new List<string>(); 199 TargetVariableComboBox.SelectedText = ""; 200 GC.Collect(); 201 var token = _cts.Token; 202 var ds = await Task.Run<Dataset>(() => _variablesLoader.GetPreviewDataset(_mlConnector, token), token); 203 GC.Collect(); 204 205 if (ds != null) { 206 _values = ds; 207 PreviewDatasetMatrix.Content = _values; 208 TargetVariableComboBox.DataSource = _values.VariableNames; 209 210 ErrorTextBox.Text = String.Empty; 211 ErrorTextBox.Visible = false; 212 OkButton.Enabled = true; 213 } 192 214 } catch (Exception ex) { 193 215 if (ex is IOException || ex is InvalidOperationException || ex is ArgumentException) { 194 216 ErrorOccured(ex.Message); 217 } else if (ex is OutOfMemoryException) { 218 ErrorOccured(ex.Message + " Amount of the given data is too big."); 195 219 } else { 196 220 throw; … … 199 223 UpdateStatus("Done"); 200 224 } 201 202 /// <summary>203 /// Displays the values of a given timeseries at the preview dataset matrix.204 /// </summary>205 /// <param name="timeseries"></param>206 private async void DisplayLoadedValuesAsync(MLTimeseries timeseries) {207 PreviewDatasetMatrix.Content = null;208 IEnumerable<string> variableNamesWithType = GetVariableNamesWithType(timeseries);209 var values = await Task.Run<double[,]>(() => GetValuesForDataset(timeseries));210 _values = new Dataset(variableNamesWithType, values);211 PreviewDatasetMatrix.Content = _values;212 SetPossibleTargetVariables(timeseries);213 }214 215 /// <summary>216 /// Sets the entries of the combobox for the target variable.217 /// </summary>218 /// <param name="timeseries"></param>219 protected void SetPossibleTargetVariables(MLTimeseries timeseries) {220 if (timeseries != null) {221 TargetVariableComboBox.DataSource = timeseries.DataHeader;222 }223 }224 225 /// <summary>226 /// Returns a list with all selected variable names for the preview dataset.227 /// </summary>228 /// <param name="timeseries"></param>229 /// <returns></returns>230 private IEnumerable<string> GetVariableNamesWithType(MLTimeseries timeseries) {231 IList<string> variableNamesWithType = timeseries.DataHeader.ToList();232 variableNamesWithType.Insert(0, "time");233 return variableNamesWithType;234 }235 236 /// <summary>237 /// Returns a two dimensional double array which contains the values including the timestamps of the given timeseries.238 /// Array[value, variable]239 /// If the amount of the data is too big, a OutOfMemoryException exception is being thrown.240 /// This exception is being cought and a message will be shown at the error message box.241 /// </summary>242 /// <param name="timeseries"></param>243 /// <returns></returns>244 private double[,] GetValuesForDataset(MLTimeseries timeseries) {245 try {246 double[,] datasetValues = new double[timeseries.Count, timeseries.DataHeader.Length + 1];247 248 int i = 0;249 foreach (var item in timeseries.Data) {250 datasetValues[i, 0] = item.Key;251 for (int j = 1; j < datasetValues.GetLength(1); j++) {252 datasetValues[i, j] = item.Value[j - 1];253 }254 i++;255 }256 return datasetValues;257 } catch (OutOfMemoryException ex) {258 ErrorOccured(ex.Message + " Amount of the given data is too big.");259 }260 return new double[0, timeseries.DataHeader.Length + 1];261 }262 225 } 263 226 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/HeuristicLab.Problems.Instances.DataAnalysis-3.3.csproj ¶
r15912 r15926 165 165 <Compile Include="Regression\Matlab\Api\MatlabApiFactory.cs" /> 166 166 <Compile Include="Regression\Matlab\Api\MatlabConnector.cs" /> 167 <Compile Include="Regression\Matlab\Api\Types\MLVariableInfo.cs" /> 167 168 <Compile Include="Regression\Matlab\RegressionMatlabImportType.cs" /> 168 169 <Compile Include="Regression\Matlab\RegressionMatlabInstanceProvider.cs" /> -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/IMatlabConnector.cs ¶
r15912 r15926 9 9 namespace HeuristicLab.Problems.Instances.DataAnalysis.Regression.Matlab.Api { 10 10 public interface IMatlabConnector : IDisposable { 11 event Action<string> ErrorOccuredEvent; 12 11 13 /// <summary> 12 14 /// Executes a given matlab script. … … 25 27 /// </summary> 26 28 /// <returns></returns> 27 I Dictionary<string, MLDatatype> GetVariablesFromScript(string script);29 IEnumerable<MLVariableInfo> GetVariablesFromScript(string script); 28 30 29 31 /// <summary> … … 47 49 /// <returns></returns> 48 50 MLDouble GetDouble(string varName); 51 52 /// <summary> 53 /// 54 /// </summary> 55 /// <param name="varName"></param> 56 /// <returns></returns> 57 MLDoubleArray GetDoubleArray(string varName); 49 58 } 50 59 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/MatlabConnector.cs ¶
r15919 r15926 31 31 private MLApp.MLApp matLabApi; 32 32 private string workspace; 33 private object locker = new object(); 34 35 public event Action<string> ErrorOccuredEvent; 33 36 34 37 public MatlabConnector(bool showcommandWindow = false, string workspace = "base") { … … 68 71 69 72 70 public IDictionary<string, MLDatatype> GetVariablesFromScript(string script) { 71 var variables = new Dictionary<string, MLDatatype>(); 72 ExecuteScript(script); 73 public IEnumerable<MLVariableInfo> GetVariablesFromScript(string script) { 74 var variables = new List<MLVariableInfo>(); 75 try { 76 ExecuteScript(script); 77 } catch(InvalidOperationException ex) { 78 if (ErrorOccuredEvent != null) { 79 ErrorOccuredEvent.Invoke(ex.Message); 80 } 81 } 73 82 74 83 Execute("variables=whos();nrOfVariables=size(variables)"); … … 77 86 for (int i = 1; i <= len; i++) { 78 87 var varName = GetVariable(string.Format("variables({0}).name", i)) as string; 79 var varSize = GetVariable(string.Format("variables({0}).size", i)) ;88 var varSize = GetVariable(string.Format("variables({0}).size", i)) as double[,]; 80 89 var varClass = GetVariable(string.Format("variables({0}).class", i)) as string; 81 // At the moment only timeseries are supported. 82 if (varClass == "timeseries") { 83 variables.Add(varName, MLDatatype.Timeseries); 84 } 90 91 GetVariablesFromScriptRec(variables, varName, varSize, varClass); 85 92 } 86 93 87 94 return variables; 88 95 } 89 96 97 private void GetVariablesFromScriptRec(IList<MLVariableInfo> variables, string varName, double[,] varSize, string varClass) { 98 var variable = new MLVariableInfo() { 99 VarName = varName, 100 Row = varSize[0, 0], 101 Column = varSize[0, 1] 102 }; 103 if (varClass == "timeseries") { 104 variable.Datatype = MLDatatype.Timeseries; 105 variables.Add(variable); 106 } else if (varClass == "double") { 107 if (variable.Row == 1 && variable.Column == 1) { 108 variable.Datatype = MLDatatype.Double; 109 } else { 110 variable.Datatype = MLDatatype.DoubleArray; 111 } 112 variables.Add(variable); 113 } else if (varClass == "struct") { 114 Execute(string.Format("mlFieldNames = fieldnames({0})", varName)); 115 var fields = GetVariable("mlFieldNames") as object[,]; 116 117 for (int i = 0; i < fields.GetLength(0); i++) { 118 var newVarName = string.Format("{0}.{1}", varName, fields[i, 0] as string); 119 Execute(string.Format("mlClass = class({0}); mlSize = size({0});", newVarName)); 120 var newVarClass = GetVariable("mlClass") as string; 121 var newVarSize = GetVariable("mlSize") as double[,]; 122 GetVariablesFromScriptRec(variables, newVarName, newVarSize, newVarClass); 123 } 124 } 125 } 90 126 91 127 public MLTimeseries GetTimeseries(string varName) { 92 object times = GetVariable(varName + ".Time"); 93 object data = GetVariable(varName + ".Data"); 94 if (times == null || data == null) { 95 return null; 128 lock (locker) { 129 object times = GetVariable(varName + ".Time"); 130 object data = GetVariable(varName + ".Data"); 131 132 if (times == null || data == null) { 133 return null; 134 } 135 return new MLTimeseries(varName, times, data); 96 136 } 97 98 return new MLTimeseries(varName, times, data);99 137 } 100 138 101 139 public MLDouble GetDouble(string varName) { 102 140 return new MLDouble(varName, GetVariable(varName)); 141 } 142 143 144 public MLDoubleArray GetDoubleArray(string varName) { 145 return new MLDoubleArray(varName, GetVariable(varName)); 103 146 } 104 147 … … 142 185 } 143 186 } 144 145 187 } 146 188 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDatatype.cs ¶
r15912 r15926 9 9 Double, 10 10 DoubleArray, 11 Timeseries 11 Timeseries, 12 Struct, 13 Undefinded 12 14 } 13 15 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLDoubleArray.cs ¶
r15919 r15926 27 27 Name = string.Format("{0};{1}", a1.Name, a2.Name); 28 28 29 if (!Concat Feasible(a1, a2)) {29 if (!ConcatIsPossible(a1, a2)) { 30 30 throw new ArgumentException(string.Format("Cannot concat {0} and {1}. Different number of rows.", a1.Name, a2.Name)); 31 31 } 32 32 33 var numberOfColumns = a1.Columns + a2.Columns;34 _dataHeaders = new string[ numberOfColumns];35 for (int i = 0; i < numberOfColumns; i++) {33 var columns = a1.Columns + a2.Columns; 34 _dataHeaders = new string[columns]; 35 for (int i = 0; i < columns; i++) { 36 36 if (i < a1.Columns) { 37 37 _dataHeaders[i] = a1.DataHeader[i]; … … 41 41 } 42 42 43 Data = new double[a1.Rows, numberOfColumns];43 Data = new double[a1.Rows, columns]; 44 44 for (int i = 0; i < a1.Rows; i++) { 45 for (int j = 0; j < numberOfColumns; j++) {45 for (int j = 0; j < columns; j++) { 46 46 if (j < a1.Columns) { 47 47 Data[i, j] = a1.Data[i, j]; 48 48 } else { 49 49 Data[i, j] = a1.Data[i, j - a1.Columns]; 50 } 51 } 52 } 53 } 54 55 private MLDoubleArray(IEnumerable<MLDoubleArray> arrays) { 56 StringBuilder sb = new StringBuilder(); 57 foreach (var array in arrays) { 58 sb.Append(array.Name + ";"); 59 } 60 Name = sb.ToString(); 61 62 var columns = 0; 63 foreach (var array in arrays) { 64 columns += array.Columns; 65 } 66 67 var dataHeaders = new List<string>(); 68 foreach (var array in arrays) { 69 foreach (var header in array.DataHeader) { 70 dataHeaders.Add(header); 71 } 72 } 73 _dataHeaders = dataHeaders.ToArray(); 74 75 var rows = arrays.First().Rows; 76 Data = new double[rows, columns]; 77 for (int i = 0; i < rows; i++) { 78 var j = 0; 79 foreach (var array in arrays) { 80 for (int k = 0; k < array.Columns; k++) { 81 Data[i, j] = array.Data[i, k]; 82 j++; 50 83 } 51 84 } … … 57 90 /// <summary> 58 91 /// Concats two given MLDoubleArrays if their number of rows equals. 59 /// If th ey can't be concated, this method returns null.92 /// If throws an InvalidOperationException if they can't be concatenated 60 93 /// </summary> 61 94 /// <param name="a1"></param> … … 63 96 /// <returns></returns> 64 97 public static MLDoubleArray Concat(MLDoubleArray a1, MLDoubleArray a2) { 65 if (Concat Feasible(a1, a2)) {66 return null;98 if (ConcatIsPossible(a1, a2)) { 99 throw new InvalidOperationException("Concatination is not possible because of different different number of their rows."); 67 100 } 68 101 return new MLDoubleArray(a1, a2); 69 102 } 70 103 71 public static bool ConcatFeasible(MLDoubleArray a1, MLDoubleArray a2) { 104 public static MLDoubleArray Concat(IEnumerable<MLDoubleArray> arrays) { 105 if (arrays.Count() < 1) { 106 throw new ArgumentException("Given number of MLDoubleArrays is 0"); 107 } 108 if (!ConcatIsPossible(arrays)) { 109 throw new InvalidOperationException("Concatenation is not possible because of different different number of their rows."); 110 } 111 return new MLDoubleArray(arrays); 112 } 113 114 public static bool ConcatIsPossible(MLDoubleArray a1, MLDoubleArray a2) { 72 115 return a1.Rows == a2.Rows; 116 } 117 118 public static bool ConcatIsPossible(IEnumerable<MLDoubleArray> arrays) { 119 var first = arrays.First(); 120 foreach (var array in arrays) { 121 if (!ConcatIsPossible(first, array)) { 122 return false; 123 } 124 } 125 return true; 73 126 } 74 127 -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/Api/Types/MLTimeseries.cs ¶
r15919 r15926 3 3 using System.Linq; 4 4 using System.Text; 5 using System.Threading; 5 6 using System.Threading.Tasks; 6 7 … … 24 25 /// </summary> 25 26 /// <param name="timeseries"></param> 26 public MLTimeseries(IEnumerable<MLTimeseries> timeseries ) : this() {27 public MLTimeseries(IEnumerable<MLTimeseries> timeseries, CancellationToken token) : this() { 27 28 var dataHeaders = new List<string>(); 28 29 var times = new SortedSet<double>(); // The time values have to be unique and sorted. … … 64 65 65 66 foreach (var v in vs) { 67 if (token.IsCancellationRequested) { 68 return; 69 } 66 70 values[idx++] = v; 67 71 } -
TabularUnified branches/2913_MatlabScriptProblemInstanceProvider/HeuristicLab.Problems.Instances.DataAnalysis/3.3/Regression/Matlab/RegressionMatlabInstanceProvider.cs ¶
r15912 r15926 67 67 68 68 69 public IRegressionProblemData ImportData(string path, RegressionMatlabImportType type, IEnumerable< KeyValuePair<string, MLDatatype>> variableNames) {69 public IRegressionProblemData ImportData(string path, RegressionMatlabImportType type, IEnumerable<MLVariableInfo> variableNames) { 70 70 var dataset = type.Values; 71 71 var targetVar = type.TargetVariable;
Note: See TracChangeset
for help on using the changeset viewer.