Changeset 13816
- Timestamp:
- 04/29/16 17:01:10 (9 years ago)
- Location:
- branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4
- Files:
-
- 2 added
- 1 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.Designer.cs
r13815 r13816 21 21 22 22 namespace HeuristicLab.Algorithms.DataAnalysis.Views { 23 partial class GaussianProcessRegressionSolutionI teractiveRangeEstimatorView {23 partial class GaussianProcessRegressionSolutionInteractiveRangeEstimatorView { 24 24 /// <summary> 25 25 /// Required designer variable. … … 114 114 // tableLayoutPanel 115 115 // 116 this.tableLayoutPanel.AutoSize = true; 117 this.tableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 118 this.tableLayoutPanel.ColumnCount = 3; 119 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 100F)); 120 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 121 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 150F)); 116 this.tableLayoutPanel.AutoScroll = true; 117 this.tableLayoutPanel.ColumnCount = 1; 118 this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 122 119 this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill; 123 120 this.tableLayoutPanel.Location = new System.Drawing.Point(3, 16); … … 125 122 this.tableLayoutPanel.RowCount = 1; 126 123 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); 127 this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20F));128 124 this.tableLayoutPanel.Size = new System.Drawing.Size(709, 192); 129 125 this.tableLayoutPanel.TabIndex = 0; 130 126 // 131 // GaussianProcessRegressionSolution RangeEstimatorView127 // GaussianProcessRegressionSolutionInteractiveRangeEstimatorView 132 128 // 133 129 this.AllowDrop = true; 134 130 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 135 131 this.Controls.Add(this.splitContainer); 136 this.Name = "GaussianProcessRegressionSolution RangeEstimatorView";132 this.Name = "GaussianProcessRegressionSolutionInteractiveRangeEstimatorView"; 137 133 this.Size = new System.Drawing.Size(715, 591); 138 134 ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit(); … … 142 138 this.splitContainer.ResumeLayout(false); 143 139 this.configurationGroupBox.ResumeLayout(false); 144 this.configurationGroupBox.PerformLayout();145 140 this.ResumeLayout(false); 146 141 -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs
r13812 r13816 23 23 using System.Collections.Generic; 24 24 using System.Drawing; 25 using System.Globalization;26 25 using System.Linq; 27 26 using System.Windows.Forms; 28 27 using System.Windows.Forms.DataVisualization.Charting; 28 using HeuristicLab.Collections; 29 29 using HeuristicLab.Data; 30 using HeuristicLab.Data.Views;31 30 using HeuristicLab.MainForm; 32 31 using HeuristicLab.MainForm.WindowsForms; … … 38 37 [View("Interactive Estimator")] 39 38 [Content(typeof(GaussianProcessRegressionSolution))] 40 public partial class GaussianProcessRegressionSolutionIteractiveRangeEstimatorView : DataAnalysisSolutionEvaluationView { 41 const int TrackBarSteps = 1000; 42 const int DrawingSteps = 1000; 39 public partial class GaussianProcessRegressionSolutionInteractiveRangeEstimatorView 40 : DataAnalysisSolutionEvaluationView { 41 42 private const int DrawingSteps = 1000; 43 43 44 44 private const string EstimatedMeanSeriesName = "Estimated Mean"; 45 45 private const string EstimatedVarianceSeriesName = "95% Conficence Interval"; 46 46 47 private static readonly string LabelFormatString = "{0}:" + Environment.NewLine + "{1}"; 48 49 private List<string> variableNames; 50 private List<DoubleRange> ranges; 51 private List<RadioButton> radioButtons; 52 private List<TrackBar> trackBars; 53 47 private readonly List<string> dimensionNames; 48 private readonly ObservableList<DensityTrackbar> dimensionTrackbars; 54 49 55 50 private int ActiveDimension { 56 get { return radioButtons.FindIndex(rb => rb.Checked); }51 get { return dimensionTrackbars.FindIndex(tb => tb.Checked); } 57 52 } 58 53 … … 61 56 set { base.Content = value; } 62 57 } 63 public GaussianProcessRegressionSolutionIteractiveRangeEstimatorView() 64 : base() { 65 variableNames = new List<string>(); 66 ranges = new List<DoubleRange>(); 67 radioButtons = new List<RadioButton>(); 68 trackBars = new List<TrackBar>(); 58 59 public GaussianProcessRegressionSolutionInteractiveRangeEstimatorView() 60 : base() { 61 dimensionNames = new List<string>(); 62 63 dimensionTrackbars = new ObservableList<DensityTrackbar>(); 64 dimensionTrackbars.ItemsAdded += (sender, args) => { 65 ForEach(args.Items.Select(i => i.Value), RegisterEvents); 66 }; 67 dimensionTrackbars.ItemsRemoved += (sender, args) => { 68 ForEach(args.Items.Select(i => i.Value), DeregisterEvents); 69 }; 70 dimensionTrackbars.CollectionReset += (sender, args) => { 71 ForEach(args.OldItems.Select(i => i.Value), DeregisterEvents); 72 ForEach(args.Items.Select(i => i.Value), RegisterEvents); 73 }; 74 69 75 70 76 InitializeComponent(); 71 tableLayoutPanel.HorizontalScroll.Maximum = 0; 72 tableLayoutPanel.AutoScroll = false;73 tableLayoutPanel.HorizontalScroll.Visible = false;74 tableLayoutPanel. AutoScroll = true;75 76 // configure axis77 78 // Avoid additional horizontal scrollbar 79 var vertScrollWidth = SystemInformation.VerticalScrollBarWidth; 80 tableLayoutPanel.Padding = new Padding(0, 0, vertScrollWidth, 0); 81 82 // Configure axis 77 83 chart.CustomizeAllChartAreas(); 78 84 chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; … … 88 94 chart.Series.Clear(); 89 95 chart.ChartAreas[0].AxisX.StripLines.Clear(); 90 if (Content == null ) return;91 92 double minX = ranges[ActiveDimension].Start;93 double maxX = ranges[ActiveDimension].End;96 if (Content == null || ActiveDimension < 0) return; 97 98 double minX = dimensionTrackbars[ActiveDimension].Limits.Lower; 99 double maxX = dimensionTrackbars[ActiveDimension].Limits.Upper; 94 100 decimal stepSize = (decimal)((maxX - minX) / DrawingSteps); 95 96 //double axisMin, axisMax, axisInterval;97 //ChartUtil.CalculateAxisInterval(minX, maxX, 10, out axisMin, out axisMax, out axisInterval);98 //decimal axisStepsSize = (decimal)((maxX - minX) / DrawingSteps);99 101 100 102 // Build dataset 101 103 var activeXs = Enumerable.Range(0, DrawingSteps).Select(i => (decimal)minX + i * stepSize).ToList(); 102 var fixedXs = trackBars.Zip(ranges, (t, r) => (decimal)r.Start + ((decimal)r.End - (decimal)r.Start)/TrackBarSteps*t.Value).ToList();103 var values = new double[DrawingSteps, variableNames.Count];104 var fixedXs = dimensionTrackbars.Select(tb => tb.Value).ToList(); 105 var values = new double[DrawingSteps, dimensionNames.Count]; 104 106 for (int r = 0; r < DrawingSteps; r++) { 105 for (int c = 0; c < variableNames.Count; c++) {107 for (int c = 0; c < dimensionNames.Count; c++) { 106 108 values[r, c] = (double)(c == ActiveDimension ? activeXs[r] : fixedXs[c]); 107 109 } 108 110 } 109 var dataset = new Dataset( variableNames, values);111 var dataset = new Dataset(dimensionNames, values); 110 112 111 113 // Estimations … … 119 121 chart.ChartAreas[0].AxisX.Interval = (maxX - minX) / 10; 120 122 123 // ToDo only databind and put config in codebehind 121 124 chart.Series.Add(EstimatedVarianceSeriesName); 122 125 chart.Series[EstimatedVarianceSeriesName].LegendText = EstimatedVarianceSeriesName; … … 132 135 var upper = means.Zip(variances, GetUpperConfBound).ToList(); 133 136 chart.Series[EstimatedVarianceSeriesName].Points.DataBindXY(activeXs, lower, upper); 134 //InsertEmptyPoints(chart.Series[EstimatedVarianceSeriesName]);135 136 137 chart.Series[EstimatedMeanSeriesName].Points.DataBindXY(activeXs, means); 137 //InsertEmptyPoints(chart.Series[EstimatedMeanSeriesName]);138 138 139 139 // Update StripLines 140 var trainingValues = Content.ProblemData.Dataset.GetDoubleValues(variableNames[ActiveDimension], Content.ProblemData.TrainingIndices); 140 var trainingValues = Content.ProblemData.Dataset.GetDoubleValues(dimensionNames[ActiveDimension], 141 Content.ProblemData.TrainingIndices); 141 142 var trainingRange = new DoubleRange(trainingValues.Min(), trainingValues.Max()); 142 143 if (minX < trainingRange.Start) … … 144 145 if (maxX > trainingRange.End) 145 146 CreateAndAddStripLine(trainingRange.End, maxX, Color.FromArgb(40, 223, 58, 2), Color.Transparent); 147 148 // Update axis description 149 chart.ChartAreas[0].AxisX.Title = dimensionNames[ActiveDimension]; 146 150 } 147 151 … … 163 167 tableLayoutPanel.Controls.Clear(); 164 168 165 variableNames.Clear(); 166 ranges.Clear(); 167 radioButtons.Clear(); 168 trackBars.Clear(); 169 169 dimensionNames.Clear(); 170 dimensionTrackbars.Clear(); 170 171 171 172 if (Content == null) { … … 175 176 } 176 177 177 variableNames.AddRange(Content.ProblemData.AllowedInputVariables); 178 for (int i = 0; i < variableNames.Count; i++) { 179 var values = Content.ProblemData.Dataset.GetDoubleValues(variableNames[i], Content.ProblemData.AllIndices); 178 dimensionNames.AddRange(Content.ProblemData.AllowedInputVariables); 179 var ranges = new List<DoubleLimit>(); 180 for (int i = 0; i < dimensionNames.Count; i++) { 181 var values = Content.ProblemData.Dataset.GetDoubleValues(dimensionNames[i], Content.ProblemData.AllIndices); 180 182 double min, max, interval; 181 183 ChartUtil.CalculateAxisInterval(values.Min(), values.Max(), 10, out min, out max, out interval); 182 ranges.Add(new Double Range(min, max));183 } 184 185 tableLayoutPanel.RowCount = variableNames.Count;186 while (tableLayoutPanel.RowStyles.Count < variableNames.Count)184 ranges.Add(new DoubleLimit(min, max)); 185 } 186 187 tableLayoutPanel.RowCount = dimensionNames.Count; 188 while (tableLayoutPanel.RowStyles.Count < dimensionNames.Count) 187 189 tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize)); 188 190 189 for (int i = 0; i < variableNames.Count; i++) { 190 var radioButton = new RadioButton { 191 Text = string.Format(LabelFormatString, variableNames[i], ranges[i].Start + (ranges[i].End - ranges[i].Start) / 2), 192 Checked = i == 0, 193 Anchor = AnchorStyles.Top | AnchorStyles.Left, 194 AutoSize = true, 195 }; 196 radioButton.CheckedChanged += radioButton_CheckedChanged; 197 var trackBar = new TrackBar { 198 Minimum = 0, 199 Maximum = TrackBarSteps, 200 Value = TrackBarSteps / 2, 201 TickFrequency = TrackBarSteps / 10, 202 LargeChange = TrackBarSteps / 10, 203 Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right, 204 Enabled = i != 0 205 }; 206 trackBar.ValueChanged += trackBar_ValueChanged; 207 var rangeView = new DoubleRangeView { 208 Content = ranges[i], 209 Anchor = AnchorStyles.Top | AnchorStyles.Right, 210 }; 211 rangeView.Content.ValueChanged += rangeView_ValueChanged; 212 213 tableLayoutPanel.RowStyles[i].SizeType = SizeType.AutoSize; 214 tableLayoutPanel.Controls.Add(radioButton, 0, i); 215 tableLayoutPanel.Controls.Add(trackBar, 1, i); 216 tableLayoutPanel.Controls.Add(rangeView, 2, i); 217 218 radioButtons.Add(radioButton); 219 trackBars.Add(trackBar); 220 } 191 for (int i = 0; i < dimensionNames.Count; i++) { 192 var name = dimensionNames[i]; 193 var trainingData = 194 Content.ProblemData.Dataset.GetDoubleValues(name, Content.ProblemData.TrainingIndices).ToList(); 195 196 var dimensionTrackbar = new DensityTrackbar(name, ranges[i], trainingData); 197 198 // events registered automatically 199 dimensionTrackbars.Add(dimensionTrackbar); 200 201 dimensionTrackbar.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; 202 tableLayoutPanel.Controls.Add(dimensionTrackbar, 0, i); 203 } 204 205 if (dimensionTrackbars.Any()) 206 dimensionTrackbars.First().Checked = true; 221 207 222 208 tableLayoutPanel.ResumeLayout(true); … … 224 210 } 225 211 226 private void UpdateCurrentValueLabel(int dim = -1) { 227 if (dim < 0) { 228 for (int i = 0; i < radioButtons.Count; i++) { 229 decimal value = (decimal)ranges[i].Start + ((decimal)ranges[i].End - (decimal)ranges[i].Start) / TrackBarSteps * trackBars[i].Value; 230 radioButtons[i].Text = Text = string.Format(LabelFormatString, variableNames[i], i == ActiveDimension ? "<Plotted>" : value.ToString(CultureInfo.InvariantCulture)); 231 } 232 } else { 233 decimal value = (decimal)ranges[dim].Start + ((decimal)ranges[dim].End - (decimal)ranges[dim].Start) /TrackBarSteps * trackBars[dim].Value; 234 radioButtons[dim].Text = Text = string.Format(LabelFormatString, variableNames[dim], dim == ActiveDimension ? "<Plotted>" : value.ToString(CultureInfo.InvariantCulture)); 235 } 236 } 237 238 private void radioButton_CheckedChanged(object sender, EventArgs e) { 239 var radioButton = sender as RadioButton; 240 if (radioButton == null || !radioButton.Checked) return; 241 242 int index = radioButtons.IndexOf(radioButton); 243 244 var inputVariables = Content.ProblemData.AllowedInputVariables.ToList(); 245 for (int i = 0; i < inputVariables.Count; i++) { 246 radioButtons[i].Checked = i == index; 247 trackBars[i].Enabled = i != index; 248 } 249 250 UpdateCurrentValueLabel(); 251 RedrawChart(); 252 } 253 private void trackBar_ValueChanged(object sender, EventArgs e) { 254 UpdateCurrentValueLabel(trackBars.FindIndex(t => t == sender)); 255 RedrawChart(); 256 } 257 private void rangeView_ValueChanged(object sender, EventArgs e) { 258 UpdateCurrentValueLabel(ranges.FindIndex(r => r == sender)); 212 private void RegisterEvents(DensityTrackbar trackbar) { 213 trackbar.CheckedChanged += DimensionTrackbar_CheckedChanged; 214 trackbar.ValueChanged += DimensionTrackbar_ValueChanged; 215 trackbar.LimitsChanged += DimensionTrackbar_LimitsChanged; 216 } 217 218 private void DeregisterEvents(DensityTrackbar trackbar) { 219 trackbar.CheckedChanged -= DimensionTrackbar_CheckedChanged; 220 trackbar.ValueChanged -= DimensionTrackbar_ValueChanged; 221 trackbar.LimitsChanged -= DimensionTrackbar_LimitsChanged; 222 } 223 224 private void DimensionTrackbar_CheckedChanged(object sender, EventArgs e) { 225 var trackBarSender = sender as DensityTrackbar; 226 if (trackBarSender == null || !trackBarSender.Checked) return; 227 // Uncheck all others 228 foreach (var tb in dimensionTrackbars.Except(new[] { trackBarSender })) 229 tb.Checked = false; 230 RedrawChart(); 231 } 232 233 private void DimensionTrackbar_LimitsChanged(object sender, EventArgs e) { 234 RedrawChart(); 235 } 236 237 private void DimensionTrackbar_ValueChanged(object sender, EventArgs e) { 259 238 RedrawChart(); 260 239 } 261 240 262 241 #region Events 242 263 243 protected override void RegisterContentEvents() { 264 244 base.RegisterContentEvents(); 265 Content.ModelChanged += new EventHandler(Content_ModelChanged); 266 Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged); 267 } 245 Content.ModelChanged += Content_ModelChanged; 246 Content.ProblemDataChanged += Content_ProblemDataChanged; 247 } 248 268 249 protected override void DeregisterContentEvents() { 269 250 base.DeregisterContentEvents(); 270 Content.ModelChanged -= new EventHandler(Content_ModelChanged);271 Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);251 Content.ModelChanged -= Content_ModelChanged; 252 Content.ProblemDataChanged -= Content_ProblemDataChanged; 272 253 } 273 254 … … 277 258 RedrawChart(); 278 259 } 260 279 261 private void Content_ModelChanged(object sender, EventArgs e) { 280 262 RedrawChart(); 281 263 } 264 282 265 private void Content_ProblemDataChanged(object sender, EventArgs e) { 283 266 UpdateConfigurationControls(); … … 288 271 var result = chart.HitTest(e.X, e.Y); 289 272 if (true || result.ChartArea != null && (result.ChartElementType == ChartElementType.PlottingArea || 290 result.ChartElementType == ChartElementType.Gridlines) ||291 273 result.ChartElementType == ChartElementType.Gridlines) || 274 result.ChartElementType == ChartElementType.StripLines) { 292 275 foreach (var axis in result.ChartArea.Axes) 293 276 axis.ScaleView.ZoomReset(int.MaxValue); 294 277 } 295 278 } 279 296 280 private void chart_MouseMove(object sender, MouseEventArgs e) { 297 281 //HitTestResult result = chart.HitTest(e.X, e.Y); … … 301 285 // Cursor = Cursors.Default; 302 286 } 287 303 288 private void chart_MouseDown(object sender, MouseEventArgs e) { 304 289 //HitTestResult result = chart.HitTest(e.X, e.Y); … … 307 292 //} 308 293 } 294 309 295 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 310 296 //if (chart.Series.Count != 4) return; … … 314 300 //e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black; 315 301 } 302 316 303 #endregion 317 304 318 305 #region Helper 306 319 307 private double GetLowerConfBound(double m, double s2) { 320 308 return m - 1.96 * Math.Sqrt(s2); 321 309 } 310 322 311 private double GetUpperConfBound(double m, double s2) { 323 312 return m + 1.96 * Math.Sqrt(s2); 324 313 } 314 315 public static void ForEach<T>(IEnumerable<T> source, Action<T> action) { 316 foreach (T item in source) 317 action(item); 318 } 319 325 320 #endregion 326 321 } -
branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj
r13812 r13816 195 195 <DependentUpon>GaussianProcessRegressionSolutionEstimatedValuesView.cs</DependentUpon> 196 196 </Compile> 197 <Compile Include="DensityTrackbar.cs"> 198 <SubType>UserControl</SubType> 199 </Compile> 200 <Compile Include="DensityTrackbar.Designer.cs"> 201 <DependentUpon>DensityTrackbar.cs</DependentUpon> 202 </Compile> 197 203 <Compile Include="MeanProdView.cs"> 198 204 <SubType>UserControl</SubType> … … 250 256 <DependentUpon>GaussianProcessRegressionSolutionLineChartView.cs</DependentUpon> 251 257 </Compile> 252 <Compile Include="GaussianProcessRegressionSolutionI teractiveRangeEstimatorView.cs">253 <SubType>UserControl</SubType> 254 </Compile> 255 <Compile Include="GaussianProcessRegressionSolutionI teractiveRangeEstimatorView.Designer.cs">256 <DependentUpon>GaussianProcessRegressionSolutionI teractiveRangeEstimatorView.cs</DependentUpon>258 <Compile Include="GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs"> 259 <SubType>UserControl</SubType> 260 </Compile> 261 <Compile Include="GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.Designer.cs"> 262 <DependentUpon>GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs</DependentUpon> 257 263 </Compile> 258 264 <Compile Include="SupportVectorMachineModelSupportVectorsView.cs">
Note: See TracChangeset
for help on using the changeset viewer.