Changeset 1043
- Timestamp:
- 12/20/08 13:54:29 (16 years ago)
- Location:
- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSet.cs
r992 r1043 45 45 private Problem problem; 46 46 public Problem Problem { 47 get { return problem; } 47 get { 48 // lazy loading of problem from DB 49 if (problem == null) { 50 IList<Statement> persistedData = Store.Select(new Statement(new Entity(Ontology.CedmaNameSpace + Guid), Ontology.PredicateSerializedData, Ontology.AnyEntity)); 51 if (persistedData.Count == 1) { 52 Literal persistedLiteral = (Literal)persistedData[0].Property; 53 this.problem = (Problem)PersistenceManager.RestoreFromGZip(Convert.FromBase64String((string)persistedLiteral.Value)); 54 } else 55 this.problem = new Problem(); // no entry in the DB => create a new problem 56 } 57 return problem; 58 } 48 59 } 49 60 … … 52 63 guid = Guid.NewGuid(); 53 64 name = "Data set"; 54 problem = new Problem();55 65 } 56 66 … … 60 70 guid = new Guid(dataSetEntity.Uri.Remove(0, Ontology.CedmaNameSpace.Length)); 61 71 IList<Statement> names = store.Select(new Statement(dataSetEntity, Ontology.PredicateName, Ontology.AnyEntity)); 62 if (names.Count > 0) name = (string)((Literal)names[0].Property).Value;72 if (names.Count > 0) name = (string)((Literal)names[0].Property).Value; 63 73 else name = guid.ToString(); 64 74 } … … 67 77 Entity myEntity = new Entity(Ontology.CedmaNameSpace + Guid); 68 78 Store.Add(new Statement(myEntity, Ontology.PredicateInstanceOf, Ontology.TypeDataSet)); 69 Store.Add(new Statement(myEntity, Ontology.PredicateSerializedData, new Literal( PersistenceManager.SaveToGZip(problem))));79 Store.Add(new Statement(myEntity, Ontology.PredicateSerializedData, new Literal(Convert.ToBase64String(PersistenceManager.SaveToGZip(problem))))); 70 80 Store.Add(new Statement(myEntity, Ontology.PredicateName, new Literal(name))); 71 81 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/DataSetListView.cs
r992 r1043 47 47 48 48 void dataSetList_Changed(object sender, EventArgs e) { 49 UpdateControls(); 49 if (InvokeRequired) Invoke((EventHandler)dataSetList_Changed, sender, e); 50 else UpdateControls(); 50 51 } 51 52 -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/Problem.cs
r1003 r1043 30 30 31 31 namespace HeuristicLab.CEDMA.Core { 32 33 public enum LearningTask { 34 Classification, 35 Regression, 36 TimeSeries, 37 Clustering 38 } 39 32 40 /// <summary> 33 41 /// Problem describes the data mining task. … … 59 67 60 68 private int validationSamplesStart; 61 62 69 public int ValidationSamplesStart { 63 70 get { return validationSamplesStart; } 64 71 set { validationSamplesStart = value; } 65 72 } 73 66 74 private int validationSamplesEnd; 67 68 75 public int ValidationSamplesEnd { 69 76 get { return validationSamplesEnd; } … … 72 79 73 80 private int testSamplesStart; 74 75 81 public int TestSamplesStart { 76 82 get { return testSamplesStart; } 77 83 set { testSamplesStart = value; } 78 84 } 85 79 86 private int testSamplesEnd; 80 81 87 public int TestSamplesEnd { 82 88 get { return testSamplesEnd; } … … 95 101 96 102 private bool autoRegressive; 97 98 103 public bool AutoRegressive { 99 104 get { return autoRegressive; } … … 101 106 } 102 107 103 private bool timeSeries; 104 105 public bool TimeSeries { 106 get { return timeSeries; } 107 set { timeSeries = value; } 108 private LearningTask learningTask; 109 public LearningTask LearningTask { 110 get { return learningTask; } 111 set { learningTask = value; } 108 112 } 109 113 … … 118 122 return new ProblemView(this); 119 123 } 124 125 public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) { 126 XmlNode node = base.GetXmlNode(name, document, persistedObjects); 127 node.AppendChild(PersistenceManager.Persist("DataSet", dataset, document, persistedObjects)); 128 XmlAttribute trainingSamplesStartAttr = document.CreateAttribute("TrainingSamplesStart"); 129 trainingSamplesStartAttr.Value = TrainingSamplesStart.ToString(); 130 XmlAttribute trainingSamplesEndAttr = document.CreateAttribute("TrainingSamplesEnd"); 131 trainingSamplesEndAttr.Value = TrainingSamplesEnd.ToString(); 132 XmlAttribute validationSamplesStartAttr = document.CreateAttribute("ValidationSamplesStart"); 133 validationSamplesStartAttr.Value = ValidationSamplesStart.ToString(); 134 XmlAttribute validationSamplesEndAttr = document.CreateAttribute("ValidationSamplesEnd"); 135 validationSamplesEndAttr.Value = ValidationSamplesEnd.ToString(); 136 XmlAttribute testSamplesStartAttr = document.CreateAttribute("TestSamplesStart"); 137 testSamplesStartAttr.Value = TestSamplesStart.ToString(); 138 XmlAttribute testSamplesEndAttr = document.CreateAttribute("TestSamplesEnd"); 139 testSamplesEndAttr.Value = TestSamplesEnd.ToString(); 140 XmlAttribute learningTaskAttr = document.CreateAttribute("LearningTask"); 141 learningTaskAttr.Value = LearningTask.ToString(); 142 XmlAttribute autoRegressiveAttr = document.CreateAttribute("AutoRegressive"); 143 autoRegressiveAttr.Value = AutoRegressive.ToString(); 144 145 node.Attributes.Append(trainingSamplesStartAttr); 146 node.Attributes.Append(trainingSamplesEndAttr); 147 node.Attributes.Append(validationSamplesStartAttr); 148 node.Attributes.Append(validationSamplesEndAttr); 149 node.Attributes.Append(testSamplesStartAttr); 150 node.Attributes.Append(testSamplesEndAttr); 151 node.Attributes.Append(learningTaskAttr); 152 node.Attributes.Append(autoRegressiveAttr); 153 154 XmlElement targetVariablesElement = document.CreateElement("AllowedTargetVariables"); 155 targetVariablesElement.InnerText = SemiColonSeparatedList(AllowedTargetVariables); 156 XmlElement inputVariablesElement = document.CreateElement("AllowedInputVariables"); 157 inputVariablesElement.InnerText = SemiColonSeparatedList(AllowedInputVariables); 158 node.AppendChild(targetVariablesElement); 159 node.AppendChild(inputVariablesElement); 160 return node; 161 } 162 163 public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) { 164 base.Populate(node, restoredObjects); 165 dataset = (HeuristicLab.DataAnalysis.Dataset)PersistenceManager.Restore(node.SelectSingleNode("DataSet"), restoredObjects); 166 TrainingSamplesStart = int.Parse(node.Attributes["TrainingSamplesStart"].Value); 167 TrainingSamplesEnd = int.Parse(node.Attributes["TrainingSamplesEnd"].Value); 168 ValidationSamplesStart = int.Parse(node.Attributes["ValidationSamplesStart"].Value); 169 ValidationSamplesEnd = int.Parse(node.Attributes["ValidationSamplesEnd"].Value); 170 TestSamplesStart = int.Parse(node.Attributes["TestSamplesStart"].Value); 171 TestSamplesEnd = int.Parse(node.Attributes["TestSamplesEnd"].Value); 172 LearningTask = (LearningTask)Enum.Parse(typeof(LearningTask), node.Attributes["LearningTask"].Value); 173 AutoRegressive = bool.Parse(node.Attributes["AutoRegressive"].Value); 174 allowedTargetVariables.Clear(); 175 foreach (string tok in node.SelectSingleNode("AllowedTargetVariables").InnerText.Split(new string[]{";"}, StringSplitOptions.RemoveEmptyEntries)) 176 allowedTargetVariables.Add(int.Parse(tok)); 177 allowedInputVariables.Clear(); 178 foreach (string tok in node.SelectSingleNode("AllowedInputVariables").InnerText.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries)) 179 allowedInputVariables.Add(int.Parse(tok)); 180 } 181 182 private string SemiColonSeparatedList(List<int> xs) { 183 StringBuilder b = new StringBuilder(); 184 foreach (int x in xs) { 185 b = b.Append(x).Append(";"); 186 } 187 if (xs.Count > 0) b.Remove(b.Length - 1, 1); // remove last ';' 188 return b.ToString(); 189 } 120 190 } 121 191 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.Designer.cs
r1042 r1043 62 62 this.partitioningGroupBox = new System.Windows.Forms.GroupBox(); 63 63 this.openFileDialog = new System.Windows.Forms.OpenFileDialog(); 64 this.modelType = new System.Windows.Forms.ComboBox(); 65 this.taskLabel = new System.Windows.Forms.Label(); 64 66 this.targetsGroupBox.SuspendLayout(); 65 67 this.inputsGroupBox.SuspendLayout(); … … 168 170 this.datasetView.Location = new System.Drawing.Point(3, 32); 169 171 this.datasetView.Name = "datasetView"; 170 this.datasetView.Size = new System.Drawing.Size(326, 230);172 this.datasetView.Size = new System.Drawing.Size(326, 176); 171 173 this.datasetView.TabIndex = 17; 172 174 // … … 200 202 this.autoregressiveCheckBox.AutoSize = true; 201 203 this.autoregressiveCheckBox.CheckAlign = System.Drawing.ContentAlignment.MiddleRight; 202 this.autoregressiveCheckBox.Location = new System.Drawing.Point( 3, 480);204 this.autoregressiveCheckBox.Location = new System.Drawing.Point(215, 424); 203 205 this.autoregressiveCheckBox.Name = "autoregressiveCheckBox"; 204 206 this.autoregressiveCheckBox.Size = new System.Drawing.Size(102, 17); … … 212 214 this.targetsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 213 215 this.targetsGroupBox.Controls.Add(this.targetsListBox); 214 this.targetsGroupBox.Location = new System.Drawing.Point(3, 3 74);216 this.targetsGroupBox.Location = new System.Drawing.Point(3, 320); 215 217 this.targetsGroupBox.Name = "targetsGroupBox"; 216 218 this.targetsGroupBox.Size = new System.Drawing.Size(167, 100); … … 223 225 this.inputsGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 224 226 this.inputsGroupBox.Controls.Add(this.inputsListBox); 225 this.inputsGroupBox.Location = new System.Drawing.Point(176, 3 74);227 this.inputsGroupBox.Location = new System.Drawing.Point(176, 320); 226 228 this.inputsGroupBox.Name = "inputsGroupBox"; 227 229 this.inputsGroupBox.Size = new System.Drawing.Size(153, 100); … … 242 244 this.partitioningGroupBox.Controls.Add(this.testSamplesStartTextBox); 243 245 this.partitioningGroupBox.Controls.Add(this.testLabel); 244 this.partitioningGroupBox.Location = new System.Drawing.Point(3, 2 68);246 this.partitioningGroupBox.Location = new System.Drawing.Point(3, 214); 245 247 this.partitioningGroupBox.Name = "partitioningGroupBox"; 246 248 this.partitioningGroupBox.Size = new System.Drawing.Size(326, 100); … … 256 258 this.openFileDialog.Title = "Import data set from file"; 257 259 // 260 // modelType 261 // 262 this.modelType.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 263 this.modelType.FormattingEnabled = true; 264 this.modelType.Location = new System.Drawing.Point(88, 422); 265 this.modelType.Name = "modelType"; 266 this.modelType.Size = new System.Drawing.Size(121, 21); 267 this.modelType.TabIndex = 26; 268 this.modelType.SelectedValueChanged += new System.EventHandler(this.modelType_SelectedValueChanged); 269 // 270 // taskLabel 271 // 272 this.taskLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 273 this.taskLabel.AutoSize = true; 274 this.taskLabel.Location = new System.Drawing.Point(8, 425); 275 this.taskLabel.Name = "taskLabel"; 276 this.taskLabel.Size = new System.Drawing.Size(74, 13); 277 this.taskLabel.TabIndex = 27; 278 this.taskLabel.Text = "Learning task:"; 279 // 258 280 // ProblemView 259 281 // 260 282 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 261 283 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 284 this.Controls.Add(this.taskLabel); 285 this.Controls.Add(this.modelType); 262 286 this.Controls.Add(this.partitioningGroupBox); 263 287 this.Controls.Add(this.inputsGroupBox); … … 267 291 this.Controls.Add(this.importButton); 268 292 this.Name = "ProblemView"; 269 this.Size = new System.Drawing.Size(337, 500);293 this.Size = new System.Drawing.Size(337, 446); 270 294 this.targetsGroupBox.ResumeLayout(false); 271 295 this.inputsGroupBox.ResumeLayout(false); … … 297 321 private System.Windows.Forms.GroupBox partitioningGroupBox; 298 322 private System.Windows.Forms.OpenFileDialog openFileDialog; 323 private System.Windows.Forms.ComboBox modelType; 324 private System.Windows.Forms.Label taskLabel; 299 325 } 300 326 } -
branches/CEDMA-Refactoring-Ticket419/HeuristicLab.CEDMA.Core/ProblemView.cs
r1042 r1043 39 39 this.problem = problem; 40 40 InitializeComponent(); 41 foreach (LearningTask l in Enum.GetValues(typeof(LearningTask))) { 42 modelType.Items.Add(l); 43 } 44 UpdateControls(); 41 45 } 42 46 43 47 protected override void UpdateControls() { 44 48 base.UpdateControls(); 49 datasetView.Dataset = problem.DataSet; 45 50 trainingSamplesStartTextBox.Text = problem.TrainingSamplesStart.ToString(); 46 51 trainingSamplesEndTextBox.Text = problem.TrainingSamplesEnd.ToString(); … … 49 54 testSamplesStartTextBox.Text = problem.TestSamplesStart.ToString(); 50 55 testSamplesEndTextBox.Text = problem.TestSamplesEnd.ToString(); 56 autoregressiveCheckBox.Checked = problem.AutoRegressive; 57 for (int i = 0; i < modelType.Items.Count; i++) { 58 if ((LearningTask)modelType.Items[i] == problem.LearningTask) { 59 modelType.SelectedIndex = i; 60 break; 61 } 62 } 51 63 targetsListBox.Items.Clear(); 52 64 inputsListBox.Items.Clear(); … … 105 117 } 106 118 107 }108 private void ShowWarningMessageBox(Exception ex) {109 MessageBox.Show(ex.Message,110 "Warning - " + ex.GetType().Name,111 MessageBoxButtons.OK,112 MessageBoxIcon.Warning);113 }114 private void ShowErrorMessageBox(Exception ex) {115 MessageBox.Show(BuildErrorMessage(ex),116 "Error - " + ex.GetType().Name,117 MessageBoxButtons.OK,118 MessageBoxIcon.Error);119 }120 private string BuildErrorMessage(Exception ex) {121 StringBuilder sb = new StringBuilder();122 sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);123 124 while (ex.InnerException != null) {125 ex = ex.InnerException;126 sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);127 }128 return sb.ToString();129 119 } 130 120 … … 204 194 return y0 > x1; 205 195 } 196 private void ShowWarningMessageBox(Exception ex) { 197 MessageBox.Show(ex.Message, 198 "Warning - " + ex.GetType().Name, 199 MessageBoxButtons.OK, 200 MessageBoxIcon.Warning); 201 } 202 private void ShowErrorMessageBox(Exception ex) { 203 MessageBox.Show(BuildErrorMessage(ex), 204 "Error - " + ex.GetType().Name, 205 MessageBoxButtons.OK, 206 MessageBoxIcon.Error); 207 } 208 private string BuildErrorMessage(Exception ex) { 209 StringBuilder sb = new StringBuilder(); 210 sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace); 211 212 while (ex.InnerException != null) { 213 ex = ex.InnerException; 214 sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace); 215 } 216 return sb.ToString(); 217 } 218 219 private void modelType_SelectedValueChanged(object sender, EventArgs e) { 220 if ((LearningTask)modelType.SelectedItem == LearningTask.TimeSeries) autoregressiveCheckBox.Enabled = true; 221 else autoregressiveCheckBox.Enabled = false; 222 problem.LearningTask = (LearningTask)modelType.SelectedItem; 223 } 206 224 } 207 225 }
Note: See TracChangeset
for help on using the changeset viewer.