Changeset 15297
- Timestamp:
- 07/29/17 16:03:05 (7 years ago)
- Location:
- branches/dataset-ids-2695
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis.Views/3.4/Regression/RegressionSolutionLineChartViewBase.cs
r14531 r15297 20 20 #endregion 21 21 using System; 22 using System.Collections; 22 23 using System.Collections.Generic; 23 24 using System.Drawing; 25 using System.Globalization; 24 26 using System.Linq; 25 27 using System.Windows.Forms; 26 28 using System.Windows.Forms.DataVisualization.Charting; 29 using HeuristicLab.Common; 27 30 using HeuristicLab.MainForm; 28 31 using HeuristicLab.Visualization.ChartControlsExtensions; … … 59 62 protected abstract void GetTrainingSeries(out int[] idx, out double[] y); 60 63 61 protected abstract void GetTestSeries(out int[] x, out double[] y);62 63 protected abstract void GetAllValuesSeries(out int[] x, out double[] y);64 protected abstract void GetTestSeries(out int[] idx, out double[] y); 65 66 protected abstract void GetAllValuesSeries(out int[] idx, out double[] y); 64 67 65 68 protected virtual void RedrawChart() { 66 69 this.chart.Series.Clear(); 67 70 if (Content != null) { 71 var allIds = Content.ProblemData.AllIds; 68 72 this.chart.ChartAreas[0].AxisX.Minimum = 0; 69 this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData. Dataset.Rows - 1;73 this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.AllIndices.Last(); 70 74 71 75 this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME); 72 76 this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME; 73 77 this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine; 74 this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(), 75 Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray()); 78 var ids = Content.ProblemData.AllIds.OfType<object>().Select(o => o.ToString()).ToArray(); 79 var vals = Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray(); 80 81 for (int i = 0; i < ids.Length; i++) { 82 chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Add(new DataPoint() { AxisLabel = ids[i], XValue = i, YValues = new double[] { vals[i] } }); 83 } 84 // this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Content.ProblemData.AllIndices.ToArray(), 85 // Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray()); 86 // chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Content.ProblemData.AllIndices.ToArray(), 87 // "AxisLabel", Content.ProblemData.AllIds.OfType<object>().Select(o => o.ToString()).ToArray(), string.Empty); 76 88 // training series 77 89 this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME); … … 133 145 134 146 UpdateCursorInterval(); 135 this.UpdateStripLines();147 UpdateStripLines(); 136 148 } 137 149 } -
branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisProblemData.cs
r14843 r15297 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using System.Linq; … … 39 40 protected const string TestPartitionParameterName = "TestPartition"; 40 41 protected const string TransformationsParameterName = "Transformations"; 41 42 protected const string IdVariableParameterName = "Id Variable"; 43 protected const string EmptyIdVariableName = "-"; 42 44 #region parameter properites 43 45 //mkommend: inserted parameter caching due to performance reasons … … 58 60 } 59 61 62 private IConstrainedValueParameter<StringValue> idVariableParameter; 63 public IConstrainedValueParameter<StringValue> IdVariableParameter { 64 get { 65 if (idVariableParameter == null) idVariableParameter = (IConstrainedValueParameter<StringValue>)Parameters[IdVariableParameterName]; 66 return idVariableParameter; 67 } 68 } 69 60 70 private IFixedValueParameter<IntRange> trainingPartitionParameter; 61 71 public IFixedValueParameter<IntRange> TrainingPartitionParameter { … … 92 102 public IEnumerable<string> AllowedInputVariables { 93 103 get { return InputVariables.CheckedItems.Select(x => x.Value.Value); } 104 } 105 public string IdVariable { 106 get { return IdVariableParameter.Value.Value; } 107 // set only possible via parameter 108 } 109 public IEnumerable AllIds { 110 get { 111 var idVar = IdVariable; 112 if (idVar == EmptyIdVariableName) return Enumerable.Range(0, Dataset.Rows); 113 else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar); 114 else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar); 115 else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar); 116 else throw new NotSupportedException("The data type of the id variable is not supported"); 117 } 118 } 119 public IEnumerable TrainingIds { 120 get { 121 var idVar = IdVariable; 122 if (idVar == EmptyIdVariableName) return TrainingIndices; 123 else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar, TrainingIndices); 124 else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar, TrainingIndices); 125 else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar, TrainingIndices); 126 else throw new NotSupportedException("The data type of the id variable is not supported"); 127 } 128 } 129 public IEnumerable TestIds { 130 get { 131 var idVar = IdVariable; 132 if (idVar == EmptyIdVariableName) return TestIndices; 133 else if (Dataset.VariableHasType<double>(idVar)) return Dataset.GetDoubleValues(idVar, TestIndices); 134 else if (Dataset.VariableHasType<DateTime>(idVar)) return Dataset.GetDateTimeValues(idVar, TestIndices); 135 else if (Dataset.VariableHasType<string>(idVar)) return Dataset.GetStringValues(idVar, TestIndices); 136 else throw new NotSupportedException("The data type of the id variable is not supported"); 137 } 94 138 } 95 139 … … 152 196 TransformationsParameter.Hidden = true; 153 197 } 198 if (!Parameters.ContainsKey(IdVariableParameterName)) { 199 var allIdVars = new ItemSet<StringValue>(GetIdVariableNames()); 200 var idVar = allIdVars.First(); 201 Parameters.Add(new ConstrainedValueParameter<StringValue>(IdVariableParameterName, "", allIdVars, idVar)); 202 TransformationsParameter.Hidden = true; 203 } 154 204 RegisterEventHandlers(); 205 } 206 207 private IEnumerable<StringValue> GetIdVariableNames() { 208 // all variables with number of different values == number of rows 209 // + a separate entry for row id 210 // select separate entry for row id as default 211 // use event to update when the dataset is changed 212 var nRows = Dataset.Rows; 213 var potentialDoubleIdVars = Dataset.DoubleVariables 214 .Where(vn => Dataset.GetReadOnlyDoubleValues(vn).Distinct().Count() == nRows).ToArray(); 215 var potentialStringIdVars = Dataset.StringVariables 216 .Where(vn => Dataset.GetReadOnlyStringValues(vn).Distinct().Count() == nRows).ToArray(); 217 var potentialDateTimeIdVars = Dataset.DateTimeVariables 218 .Where(vn => Dataset.GetReadOnlyDateTimeValues(vn).Distinct().Count() == nRows).ToArray(); 219 return 220 new string[] { EmptyIdVariableName } 221 .Concat(potentialStringIdVars) 222 .Concat(potentialDateTimeIdVars) 223 .Concat(potentialDoubleIdVars) 224 .Select(s => new StringValue(s)); 155 225 } 156 226 … … 179 249 Parameters.Add(new FixedValueParameter<IntRange>(TestPartitionParameterName, "", new IntRange(testPartitionStart, testPartitionEnd))); 180 250 Parameters.Add(new FixedValueParameter<ReadOnlyItemList<ITransformation>>(TransformationsParameterName, "", transformationsList.AsReadOnly())); 181 182 251 TransformationsParameter.Hidden = true; 252 var allIdVars = new ItemSet<StringValue>(GetIdVariableNames()); 253 Parameters.Add(new ConstrainedValueParameter<StringValue>(IdVariableParameterName, "The variable to use as an ID column", allIdVars, allIdVars.First())); 183 254 184 255 ((ValueParameter<Dataset>)DatasetParameter).ReactOnValueToStringChangedAndValueItemImageChanged = false; … … 199 270 200 271 private void Parameter_ValueChanged(object sender, EventArgs e) { 272 // update list of possible id variables and set currently set id variable if possible 273 var curId = IdVariable; 274 var newIdVars = GetIdVariableNames().ToArray(); 275 var matchingIdVar = newIdVars.FirstOrDefault(var => var.Value == curId); 276 if (matchingIdVar == null) matchingIdVar = newIdVars.First(); 277 IdVariableParameter.ValidValues.Clear(); 278 var validValues = IdVariableParameter.ValidValues; 279 foreach(var entry in newIdVars) validValues.Add(entry); 280 IdVariableParameter.Value = matchingIdVar; 281 201 282 OnChanged(); 202 283 } -
branches/dataset-ids-2695/HeuristicLab.Problems.DataAnalysis/3.4/Interfaces/IDataAnalysisProblemData.cs
r14843 r15297 21 21 22 22 using System; 23 using System.Collections; 23 24 using System.Collections.Generic; 24 25 using HeuristicLab.Core; … … 32 33 ICheckedItemList<StringValue> InputVariables { get; } 33 34 IEnumerable<string> AllowedInputVariables { get; } 35 string IdVariable { get; } 34 36 35 37 double[,] AllowedInputsTrainingValues { get; } … … 39 41 IntRange TestPartition { get; } 40 42 43 IEnumerable AllIds { get; } 44 IEnumerable TrainingIds { get; } 45 IEnumerable TestIds { get; } 41 46 IEnumerable<int> AllIndices { get; } 42 47 IEnumerable<int> TrainingIndices { get; }
Note: See TracChangeset
for help on using the changeset viewer.