示例#1
0
        private void UpdateDensityChart(DensityChart densityChart, string variable, IList <int> indices = null)
        {
            if (densityComboBox.SelectedIndex == 0)
            {
                return;
            }
            if (indices == null)
            {
                indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList();
            }
            var data          = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList();
            var gradientChart = gradientCharts[variable];
            var min           = gradientChart.FixedXAxisMin;
            var max           = gradientChart.FixedXAxisMax;
            var buckets       = gradientChart.DrawingSteps;

            if (min.HasValue && max.HasValue)
            {
                densityChart.UpdateChart(data, min.Value, max.Value, buckets);
                densityChart.Width = gradientChart.Width;

                var gcPlotPosition = gradientChart.InnerPlotPosition;
                densityChart.Left  = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width);
                densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width);

                densityChart.Visible = true;
            }

            gradientChart.UpdateTitlePosition();
        }
        private void UpdateDensityChart(DensityChart densityChart, string variable, IList <int> indices = null)
        {
            if (densityComboBox.SelectedIndex == 0)
            {
                return;
            }
            if (indices == null)
            {
                indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList();
            }
            if (Content.ProblemData.Dataset.VariableHasType <double>(variable))
            {
                var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList();
                var plot = partialDependencePlots[variable] as PartialDependencePlot;
                if (plot != null)
                {
                    var min     = plot.FixedXAxisMin;
                    var max     = plot.FixedXAxisMax;
                    var buckets = plot.DrawingSteps;
                    if (min.HasValue && max.HasValue)
                    {
                        densityChart.UpdateChart(data, min.Value, max.Value, buckets);
                        densityChart.Width = plot.Width;

                        var gcPlotPosition = plot.InnerPlotPosition;
                        densityChart.Left  = (int)(gcPlotPosition.X / 100.0 * plot.Width);
                        densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * plot.Width);

                        densityChart.Visible = true;
                    }
                    plot.UpdateTitlePosition();
                }
            }
            else if (Content.ProblemData.Dataset.VariableHasType <string>(variable))
            {
                var data = Content.ProblemData.Dataset.GetStringValues(variable).ToList();
                var plot = partialDependencePlots[variable] as FactorPartialDependencePlot;
                if (plot != null)
                {
                    densityChart.UpdateChart(data);
                    densityChart.Width = plot.Width;

                    var gcPlotPosition = plot.InnerPlotPosition;
                    densityChart.Left  = (int)(gcPlotPosition.X / 100.0 * plot.Width);
                    densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * plot.Width);

                    densityChart.Visible = true;

                    plot.UpdateTitlePosition();
                }
            }
        }
        protected override void OnContentChanged()
        {
            base.OnContentChanged();
            if (Content == null)
            {
                return;
            }
            var problemData = Content.ProblemData;

            if (sharedFixedVariables != null)
            {
                sharedFixedVariables.ItemChanged -= SharedFixedVariables_ItemChanged;
                sharedFixedVariables.Reset       -= SharedFixedVariables_Reset;
            }

            // Init Y-axis range
            double min = double.MaxValue, max = double.MinValue;
            var    trainingTarget = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);

            foreach (var t in trainingTarget)
            {
                if (t < min)
                {
                    min = t;
                }
                if (t > max)
                {
                    max = t;
                }
            }
            double       range = max - min;
            const double scale = 1.0 / 3.0;
            double       axisMin, axisMax, axisInterval;

            ChartUtil.CalculateAxisInterval(min - scale * range, max + scale * range, 5, out axisMin, out axisMax, out axisInterval);
            automaticYAxisCheckBox.Checked = false;
            limitView.ReadOnly             = false;
            limitView.Content.Lower        = axisMin;
            limitView.Content.Upper        = axisMax;

            // create dataset of problemData input variables and model input variables
            // necessary workaround to have the variables in the occuring order
            var inputvariables =
                new HashSet <string>(Content.ProblemData.AllowedInputVariables.Union(Content.Model.VariablesUsedForPrediction));
            var allowedInputVariables =
                Content.ProblemData.Dataset.VariableNames.Where(v => inputvariables.Contains(v)).ToList();

            var doubleVariables      = allowedInputVariables.Where(problemData.Dataset.VariableHasType <double>);
            var doubleVariableValues = (IEnumerable <IList>)doubleVariables.Select(x => new List <double> {
                problemData.Dataset.GetDoubleValue(x, 0)
            });

            var factorVariables      = allowedInputVariables.Where(problemData.Dataset.VariableHasType <string>);
            var factorVariableValues = (IEnumerable <IList>)factorVariables.Select(x => new List <string> {
                problemData.Dataset.GetStringValue(x, 0)
            });

            sharedFixedVariables = new ModifiableDataset(doubleVariables.Concat(factorVariables), doubleVariableValues.Concat(factorVariableValues));
            variableValuesModeComboBox.SelectedItem = "Median"; // triggers UpdateVariableValue and changes shardFixedVariables

            // create controls
            partialDependencePlots.Clear();
            densityCharts.Clear();
            groupingPanels.Clear();
            foreach (var variableName in doubleVariables)
            {
                var plot = CreatePartialDependencePlot(variableName, sharedFixedVariables);
                partialDependencePlots.Add(variableName, plot);

                var densityChart = new DensityChart()
                {
                    Anchor  = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
                    Margin  = Padding.Empty,
                    Height  = 12,
                    Visible = false,
                    Top     = (int)(plot.Height * 0.1),
                };
                densityCharts.Add(variableName, densityChart);

                plot.ZoomChanged += (o, e) => {
                    var pdp     = (PartialDependencePlot)o;
                    var density = densityCharts[pdp.FreeVariable];
                    density.Visible = densityComboBox.SelectedIndex != 0 && !pdp.IsZoomed;
                    if (density.Visible)
                    {
                        UpdateDensityChart(density, pdp.FreeVariable);
                    }
                };
                plot.SizeChanged += (o, e) => {
                    var pdp     = (PartialDependencePlot)o;
                    var density = densityCharts[pdp.FreeVariable];
                    density.Top = (int)(pdp.Height * 0.1);
                };

                // Initially, the inner plot areas are not initialized for hidden charts (scrollpanel, ...)
                // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
                plot.ChartPostPaint += OnPartialDependencePlotPostPaint;

                var panel = new Panel()
                {
                    Dock      = DockStyle.Fill,
                    Margin    = Padding.Empty,
                    BackColor = Color.White
                };

                panel.Controls.Add(densityChart);
                panel.Controls.Add(plot);
                groupingPanels.Add(variableName, panel);
            }
            foreach (var variableName in factorVariables)
            {
                var plot = CreateFactorPartialDependencePlot(variableName, sharedFixedVariables);
                partialDependencePlots.Add(variableName, plot);

                var densityChart = new DensityChart()
                {
                    Anchor  = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
                    Margin  = Padding.Empty,
                    Height  = 12,
                    Visible = false,
                    Top     = (int)(plot.Height * 0.1),
                };
                densityCharts.Add(variableName, densityChart);
                plot.ZoomChanged += (o, e) => {
                    var pdp     = (FactorPartialDependencePlot)o;
                    var density = densityCharts[pdp.FreeVariable];
                    density.Visible = densityComboBox.SelectedIndex != 0 && !pdp.IsZoomed;
                    if (density.Visible)
                    {
                        UpdateDensityChart(density, pdp.FreeVariable);
                    }
                };
                plot.SizeChanged += (o, e) => {
                    var pdp     = (FactorPartialDependencePlot)o;
                    var density = densityCharts[pdp.FreeVariable];
                    density.Top = (int)(pdp.Height * 0.1);
                };

                // Initially, the inner plot areas are not initialized for hidden charts (scrollpanel, ...)
                // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
                plot.ChartPostPaint += OnFactorPartialDependencePlotPostPaint;

                var panel = new Panel()
                {
                    Dock      = DockStyle.Fill,
                    Margin    = Padding.Empty,
                    BackColor = Color.White
                };

                panel.Controls.Add(densityChart);
                panel.Controls.Add(plot);
                groupingPanels.Add(variableName, panel);
            }
            // update variable list
            variableListView.ItemChecked -= variableListView_ItemChecked;
            variableListView.Items.Clear();
            foreach (var variable in allowedInputVariables)
            {
                variableListView.Items.Add(key: variable, text: variable, imageIndex: 0);
            }

            foreach (var variable in Content.Model.VariablesUsedForPrediction)
            {
                variableListView.Items[variable].Checked = true;
            }
            variableListView.ItemChecked += variableListView_ItemChecked;

            sharedFixedVariables.ItemChanged += SharedFixedVariables_ItemChanged;
            sharedFixedVariables.Reset       += SharedFixedVariables_Reset;

            rowNrNumericUpDown.Maximum = Content.ProblemData.Dataset.Rows - 1;

            RecalculateAndRelayoutCharts();
        }
示例#4
0
        protected override void OnContentChanged()
        {
            base.OnContentChanged();
            if (Content == null)
            {
                return;
            }
            var problemData = Content.ProblemData;

            // Init Y-axis range
            double min = double.MaxValue, max = double.MinValue;
            var    trainingTarget = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);

            foreach (var t in trainingTarget)
            {
                if (t < min)
                {
                    min = t;
                }
                if (t > max)
                {
                    max = t;
                }
            }
            double       range = max - min;
            const double scale = 1.0 / 3.0;
            double       axisMin, axisMax, axisInterval;

            ChartUtil.CalculateAxisInterval(min - scale * range, max + scale * range, 5, out axisMin, out axisMax, out axisInterval);
            automaticYAxisCheckBox.Checked = false;
            limitView.ReadOnly             = false;
            limitView.Content.Lower        = axisMin;
            limitView.Content.Upper        = axisMax;

            // create dataset
            var allowedInputVariables = Content.ProblemData.AllowedInputVariables;
            var variableValues        = allowedInputVariables.Select(x => new List <double> {
                problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median()
            });
            var sharedFixedVariables = new ModifiableDataset(allowedInputVariables, variableValues);

            // create controls
            gradientCharts.Clear();
            densityCharts.Clear();
            groupingPanels.Clear();
            foreach (var variableName in allowedInputVariables)
            {
                var gradientChart = CreateGradientChart(variableName, sharedFixedVariables);
                gradientCharts.Add(variableName, gradientChart);

                var densityChart = new DensityChart()
                {
                    Anchor  = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
                    Margin  = Padding.Empty,
                    Height  = 12,
                    Visible = false,
                    Top     = (int)(gradientChart.Height * 0.1),
                };
                densityCharts.Add(variableName, densityChart);

                gradientChart.ZoomChanged += (o, e) => {
                    var gradient = (GradientChart)o;
                    var density  = densityCharts[gradient.FreeVariable];
                    density.Visible = densityComboBox.SelectedIndex != 0 && !gradient.IsZoomed;
                    if (density.Visible)
                    {
                        UpdateDensityChart(density, gradient.FreeVariable);
                    }
                };
                gradientChart.SizeChanged += (o, e) => {
                    var gradient = (GradientChart)o;
                    var density  = densityCharts[gradient.FreeVariable];
                    density.Top = (int)(gradient.Height * 0.1);
                };

                // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...)
                // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
                gradientChart.ChartPostPaint += OnGradientChartOnChartPostPaint;

                var panel = new Panel()
                {
                    Dock      = DockStyle.Fill,
                    Margin    = Padding.Empty,
                    BackColor = Color.White
                };

                panel.Controls.Add(densityChart);
                panel.Controls.Add(gradientChart);
                groupingPanels.Add(variableName, panel);
            }

            // update variable list
            variableListView.ItemChecked -= variableListView_ItemChecked;
            variableListView.Items.Clear();
            foreach (var variable in allowedInputVariables)
            {
                variableListView.Items.Add(key: variable, text: variable, imageIndex: 0);
            }

            foreach (var variable in Content.Model.VariablesUsedForPrediction)
            {
                variableListView.Items[variable].Checked = true;
            }
            variableListView.ItemChecked += variableListView_ItemChecked;

            RecalculateAndRelayoutCharts();
        }
    protected override void OnContentChanged() {
      base.OnContentChanged();
      if (Content == null) return;
      var problemData = Content.ProblemData;

      // Init Y-axis range
      double min = double.MaxValue, max = double.MinValue;
      var trainingTarget = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices);
      foreach (var t in trainingTarget) {
        if (t < min) min = t;
        if (t > max) max = t;
      }
      double range = max - min;
      const double scale = 1.0 / 3.0;
      double axisMin, axisMax, axisInterval;
      ChartUtil.CalculateAxisInterval(min - scale * range, max + scale * range, 5, out axisMin, out axisMax, out axisInterval);
      automaticYAxisCheckBox.Checked = false;
      limitView.ReadOnly = false;
      limitView.Content.Lower = axisMin;
      limitView.Content.Upper = axisMax;

      // create dataset
      var allowedInputVariables = Content.ProblemData.AllowedInputVariables;
      var variableValues = allowedInputVariables.Select(x => new List<double> { problemData.Dataset.GetDoubleValues(x, problemData.TrainingIndices).Median() });
      var sharedFixedVariables = new ModifiableDataset(allowedInputVariables, variableValues);

      // create controls
      gradientCharts.Clear();
      densityCharts.Clear();
      groupingPanels.Clear();
      foreach (var variableName in allowedInputVariables) {
        var gradientChart = CreateGradientChart(variableName, sharedFixedVariables);
        gradientCharts.Add(variableName, gradientChart);

        var densityChart = new DensityChart() {
          Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right,
          Margin = Padding.Empty,
          Height = 12,
          Visible = false,
          Top = (int)(gradientChart.Height * 0.1),
        };
        densityCharts.Add(variableName, densityChart);

        gradientChart.ZoomChanged += (o, e) => {
          var gradient = (GradientChart)o;
          var density = densityCharts[gradient.FreeVariable];
          density.Visible = densityComboBox.SelectedIndex != 0 && !gradient.IsZoomed;
          if (density.Visible)
            UpdateDensityChart(density, gradient.FreeVariable);
        };
        gradientChart.SizeChanged += (o, e) => {
          var gradient = (GradientChart)o;
          var density = densityCharts[gradient.FreeVariable];
          density.Top = (int)(gradient.Height * 0.1);
        };

        // Initially, the inner plot areas are not initialized for hidden charts (scollpanel, ...)
        // This event handler listens for the paint event once (where everything is already initialized) to do some manual layouting.
        gradientChart.ChartPostPaint += OnGradientChartOnChartPostPaint;

        var panel = new Panel() {
          Dock = DockStyle.Fill,
          Margin = Padding.Empty,
          BackColor = Color.White
        };

        panel.Controls.Add(densityChart);
        panel.Controls.Add(gradientChart);
        groupingPanels.Add(variableName, panel);
      }

      // update variable list
      variableListView.ItemChecked -= variableListView_ItemChecked;
      variableListView.Items.Clear();
      foreach (var variable in allowedInputVariables)
        variableListView.Items.Add(key: variable, text: variable, imageIndex: 0);

      foreach (var variable in Content.Model.VariablesUsedForPrediction)
        variableListView.Items[variable].Checked = true;
      variableListView.ItemChecked += variableListView_ItemChecked;

      RecalculateAndRelayoutCharts();
    }
    private void UpdateDensityChart(DensityChart densityChart, string variable, IList<int> indices = null) {
      if (densityComboBox.SelectedIndex == 0)
        return;
      if (indices == null) {
        indices = GetDensityIndices(densityComboBox.SelectedIndex).ToList();
      }
      var data = Content.ProblemData.Dataset.GetDoubleValues(variable, indices).ToList();
      var gradientChart = gradientCharts[variable];
      var min = gradientChart.FixedXAxisMin;
      var max = gradientChart.FixedXAxisMax;
      var buckets = gradientChart.DrawingSteps;
      if (min.HasValue && max.HasValue) {
        densityChart.UpdateChart(data, min.Value, max.Value, buckets);
        densityChart.Width = gradientChart.Width;

        var gcPlotPosition = gradientChart.InnerPlotPosition;
        densityChart.Left = (int)(gcPlotPosition.X / 100.0 * gradientChart.Width);
        densityChart.Width = (int)(gcPlotPosition.Width / 100.0 * gradientChart.Width);

        densityChart.Visible = true;
      }

      gradientChart.UpdateTitlePosition();
    }