Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13816


Ignore:
Timestamp:
04/29/16 17:01:10 (9 years ago)
Author:
pfleck
Message:

#2597:

  • Fixed typo in class/filename.
  • Added new control that shows density information adjacent to the trackbar.
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  
    2121
    2222namespace HeuristicLab.Algorithms.DataAnalysis.Views {
    23   partial class GaussianProcessRegressionSolutionIteractiveRangeEstimatorView {
     23  partial class GaussianProcessRegressionSolutionInteractiveRangeEstimatorView {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    114114      // tableLayoutPanel
    115115      //
    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());
    122119      this.tableLayoutPanel.Dock = System.Windows.Forms.DockStyle.Fill;
    123120      this.tableLayoutPanel.Location = new System.Drawing.Point(3, 16);
     
    125122      this.tableLayoutPanel.RowCount = 1;
    126123      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));
    128124      this.tableLayoutPanel.Size = new System.Drawing.Size(709, 192);
    129125      this.tableLayoutPanel.TabIndex = 0;
    130126      //
    131       // GaussianProcessRegressionSolutionRangeEstimatorView
     127      // GaussianProcessRegressionSolutionInteractiveRangeEstimatorView
    132128      //
    133129      this.AllowDrop = true;
    134130      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
    135131      this.Controls.Add(this.splitContainer);
    136       this.Name = "GaussianProcessRegressionSolutionRangeEstimatorView";
     132      this.Name = "GaussianProcessRegressionSolutionInteractiveRangeEstimatorView";
    137133      this.Size = new System.Drawing.Size(715, 591);
    138134      ((System.ComponentModel.ISupportInitialize)(this.chart)).EndInit();
     
    142138      this.splitContainer.ResumeLayout(false);
    143139      this.configurationGroupBox.ResumeLayout(false);
    144       this.configurationGroupBox.PerformLayout();
    145140      this.ResumeLayout(false);
    146141
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs

    r13812 r13816  
    2323using System.Collections.Generic;
    2424using System.Drawing;
    25 using System.Globalization;
    2625using System.Linq;
    2726using System.Windows.Forms;
    2827using System.Windows.Forms.DataVisualization.Charting;
     28using HeuristicLab.Collections;
    2929using HeuristicLab.Data;
    30 using HeuristicLab.Data.Views;
    3130using HeuristicLab.MainForm;
    3231using HeuristicLab.MainForm.WindowsForms;
     
    3837  [View("Interactive Estimator")]
    3938  [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;
    4343
    4444    private const string EstimatedMeanSeriesName = "Estimated Mean";
    4545    private const string EstimatedVarianceSeriesName = "95% Conficence Interval";
    4646
    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;
    5449
    5550    private int ActiveDimension {
    56       get { return radioButtons.FindIndex(rb => rb.Checked); }
     51      get { return dimensionTrackbars.FindIndex(tb => tb.Checked); }
    5752    }
    5853
     
    6156      set { base.Content = value; }
    6257    }
    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
    6975
    7076      InitializeComponent();
    71       tableLayoutPanel.HorizontalScroll.Maximum = 0;
    72       tableLayoutPanel.AutoScroll = false;
    73       tableLayoutPanel.HorizontalScroll.Visible = false;
    74       tableLayoutPanel.AutoScroll = true;
    75 
    76       //configure axis
     77
     78      // Avoid additional horizontal scrollbar
     79      var vertScrollWidth = SystemInformation.VerticalScrollBarWidth;
     80      tableLayoutPanel.Padding = new Padding(0, 0, vertScrollWidth, 0);
     81
     82      // Configure axis
    7783      chart.CustomizeAllChartAreas();
    7884      chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
     
    8894      chart.Series.Clear();
    8995      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;
    94100      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);
    99101
    100102      // Build dataset
    101103      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];
    104106      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++) {
    106108          values[r, c] = (double)(c == ActiveDimension ? activeXs[r] : fixedXs[c]);
    107109        }
    108110      }
    109       var dataset = new Dataset(variableNames, values);
     111      var dataset = new Dataset(dimensionNames, values);
    110112
    111113      // Estimations
     
    119121      chart.ChartAreas[0].AxisX.Interval = (maxX - minX) / 10;
    120122
     123      // ToDo only databind and put config in codebehind
    121124      chart.Series.Add(EstimatedVarianceSeriesName);
    122125      chart.Series[EstimatedVarianceSeriesName].LegendText = EstimatedVarianceSeriesName;
     
    132135      var upper = means.Zip(variances, GetUpperConfBound).ToList();
    133136      chart.Series[EstimatedVarianceSeriesName].Points.DataBindXY(activeXs, lower, upper);
    134       //InsertEmptyPoints(chart.Series[EstimatedVarianceSeriesName]);
    135 
    136137      chart.Series[EstimatedMeanSeriesName].Points.DataBindXY(activeXs, means);
    137       //InsertEmptyPoints(chart.Series[EstimatedMeanSeriesName]);
    138138
    139139      // 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);
    141142      var trainingRange = new DoubleRange(trainingValues.Min(), trainingValues.Max());
    142143      if (minX < trainingRange.Start)
     
    144145      if (maxX > trainingRange.End)
    145146        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];
    146150    }
    147151
     
    163167      tableLayoutPanel.Controls.Clear();
    164168
    165       variableNames.Clear();
    166       ranges.Clear();
    167       radioButtons.Clear();
    168       trackBars.Clear();
    169 
     169      dimensionNames.Clear();
     170      dimensionTrackbars.Clear();
    170171
    171172      if (Content == null) {
     
    175176      }
    176177
    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);
    180182        double min, max, interval;
    181183        ChartUtil.CalculateAxisInterval(values.Min(), values.Max(), 10, out min, out max, out interval);
    182         ranges.Add(new DoubleRange(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)
    187189        tableLayoutPanel.RowStyles.Add(new RowStyle(SizeType.AutoSize));
    188190
    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;
    221207
    222208      tableLayoutPanel.ResumeLayout(true);
     
    224210    }
    225211
    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) {
    259238      RedrawChart();
    260239    }
    261240
    262241    #region Events
     242
    263243    protected override void RegisterContentEvents() {
    264244      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
    268249    protected override void DeregisterContentEvents() {
    269250      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;
    272253    }
    273254
     
    277258      RedrawChart();
    278259    }
     260
    279261    private void Content_ModelChanged(object sender, EventArgs e) {
    280262      RedrawChart();
    281263    }
     264
    282265    private void Content_ProblemDataChanged(object sender, EventArgs e) {
    283266      UpdateConfigurationControls();
     
    288271      var result = chart.HitTest(e.X, e.Y);
    289272      if (true || result.ChartArea != null && (result.ChartElementType == ChartElementType.PlottingArea ||
    290                                        result.ChartElementType == ChartElementType.Gridlines) ||
    291                                        result.ChartElementType == ChartElementType.StripLines) {
     273                                               result.ChartElementType == ChartElementType.Gridlines) ||
     274          result.ChartElementType == ChartElementType.StripLines) {
    292275        foreach (var axis in result.ChartArea.Axes)
    293276          axis.ScaleView.ZoomReset(int.MaxValue);
    294277      }
    295278    }
     279
    296280    private void chart_MouseMove(object sender, MouseEventArgs e) {
    297281      //HitTestResult result = chart.HitTest(e.X, e.Y);
     
    301285      //  Cursor = Cursors.Default;
    302286    }
     287
    303288    private void chart_MouseDown(object sender, MouseEventArgs e) {
    304289      //HitTestResult result = chart.HitTest(e.X, e.Y);
     
    307292      //}
    308293    }
     294
    309295    private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) {
    310296      //if (chart.Series.Count != 4) return;
     
    314300      //e.LegendItems[3].Cells[1].ForeColor = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Count == 0 ? Color.Gray : Color.Black;
    315301    }
     302
    316303    #endregion
    317304
    318305    #region Helper
     306
    319307    private double GetLowerConfBound(double m, double s2) {
    320308      return m - 1.96 * Math.Sqrt(s2);
    321309    }
     310
    322311    private double GetUpperConfBound(double m, double s2) {
    323312      return m + 1.96 * Math.Sqrt(s2);
    324313    }
     314
     315    public static void ForEach<T>(IEnumerable<T> source, Action<T> action) {
     316      foreach (T item in source)
     317        action(item);
     318    }
     319
    325320    #endregion
    326321  }
  • branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Algorithms.DataAnalysis.Views/3.4/HeuristicLab.Algorithms.DataAnalysis.Views-3.4.csproj

    r13812 r13816  
    195195      <DependentUpon>GaussianProcessRegressionSolutionEstimatedValuesView.cs</DependentUpon>
    196196    </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>
    197203    <Compile Include="MeanProdView.cs">
    198204      <SubType>UserControl</SubType>
     
    250256      <DependentUpon>GaussianProcessRegressionSolutionLineChartView.cs</DependentUpon>
    251257    </Compile>
    252     <Compile Include="GaussianProcessRegressionSolutionIteractiveRangeEstimatorView.cs">
    253       <SubType>UserControl</SubType>
    254     </Compile>
    255     <Compile Include="GaussianProcessRegressionSolutionIteractiveRangeEstimatorView.Designer.cs">
    256       <DependentUpon>GaussianProcessRegressionSolutionIteractiveRangeEstimatorView.cs</DependentUpon>
     258    <Compile Include="GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs">
     259      <SubType>UserControl</SubType>
     260    </Compile>
     261    <Compile Include="GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.Designer.cs">
     262      <DependentUpon>GaussianProcessRegressionSolutionInteractiveRangeEstimatorView.cs</DependentUpon>
    257263    </Compile>
    258264    <Compile Include="SupportVectorMachineModelSupportVectorsView.cs">
Note: See TracChangeset for help on using the changeset viewer.