コード例 #1
0
        private void UpdateSeries()
        {
            if (InvokeRequired)
            {
                Invoke((Action)UpdateSeries);
            }
            else
            {
                string targetVariableName = Content.ProblemData.TargetVariable;
                var    dataset            = Content.ProblemData.Dataset;
                if (this.chart.Series[ALL_SERIES].Points.Count > 0)
                {
                    this.chart.Series[ALL_SERIES].Points.DataBindXY(dataset.GetDoubleValues(targetVariableName).ToArray(), "",
                                                                    Content.EstimatedValues.ToArray(), "");
                }
                if (this.chart.Series[TRAINING_SERIES].Points.Count > 0)
                {
                    this.chart.Series[TRAINING_SERIES].Points.DataBindXY(dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TrainingIndices).ToArray(), "",
                                                                         Content.EstimatedTrainingValues.ToArray(), "");
                }
                if (this.chart.Series[TEST_SERIES].Points.Count > 0)
                {
                    this.chart.Series[TEST_SERIES].Points.DataBindXY(dataset.GetDoubleValues(targetVariableName, Content.ProblemData.TestIndices).ToArray(), "",
                                                                     Content.EstimatedTestValues.ToArray(), "");
                }
                double max = Content.EstimatedTrainingValues
                             .Concat(Content.EstimatedTestValues
                                     .Concat(Content.EstimatedValues
                                             .Concat(dataset.GetDoubleValues(targetVariableName))))
                             .Where(v => !double.IsNaN(v) && !double.IsInfinity(v)).Max();
                double min = Content.EstimatedTrainingValues
                             .Concat(Content.EstimatedTestValues
                                     .Concat(Content.EstimatedValues
                                             .Concat(dataset.GetDoubleValues(targetVariableName))))
                             .Where(v => !double.IsNaN(v) && !double.IsInfinity(v)).Min();

                double axisMin, axisMax, axisInterval;
                ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
                this.chart.ChartAreas[0].AxisY.Title    = "Estimated " + targetVariableName;
                this.chart.ChartAreas[0].AxisY.Maximum  = axisMax;
                this.chart.ChartAreas[0].AxisY.Minimum  = axisMin;
                this.chart.ChartAreas[0].AxisY.Interval = axisInterval;
                this.chart.ChartAreas[0].AxisX.Title    = targetVariableName;
                this.chart.ChartAreas[0].AxisX.Maximum  = axisMax;
                this.chart.ChartAreas[0].AxisX.Minimum  = axisMin;
                this.chart.ChartAreas[0].AxisX.Interval = axisInterval;

                UpdateCursorInterval();
            }
        }
コード例 #2
0
        protected override DataTable CreateDataTable(string variableName)
        {
            var dt  = new DataTable();
            var row = Content.CreateDataRow(variableName, DataRowVisualProperties.DataRowChartType.Line);

            dt.Rows.Add(row);

            var validValues = row.Values.Where(x => !double.IsNaN(x) && !double.IsInfinity(x)).ToList();

            if (validValues.Any())
            {
                try {
                    double axisMin, axisMax, axisInterval;
                    ChartUtil.CalculateOptimalAxisInterval(validValues.Min(), validValues.Max(), out axisMin, out axisMax, out axisInterval);
                    dt.VisualProperties.YAxisMinimumAuto       = false;
                    dt.VisualProperties.YAxisMaximumAuto       = false;
                    dt.VisualProperties.YAxisMinimumFixedValue = axisMin;
                    dt.VisualProperties.YAxisMaximumFixedValue = axisMax;
                } catch (ArgumentOutOfRangeException) { }
            }
            return(dt);
        }
        protected virtual void RedrawChart()
        {
            this.chart.Series.Clear();
            if (Content != null)
            {
                this.chart.ChartAreas[0].AxisX.Minimum = 0;
                this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.Dataset.Rows - 1;

                this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
                                                                                Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
                // training series
                this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText            = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType             = SeriesChartType.FastLine;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
                int[]    trainingIdx;
                double[] trainingY;
                GetTrainingSeries(out trainingIdx, out trainingY);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(trainingIdx, trainingY);
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;

                // test series
                this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                int[]    testIdx;
                double[] testY;
                GetTestSeries(out testIdx, out testY);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(testIdx, testY);
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;

                // series of remaining points
                int[]    allIdx;
                double[] allEstimatedValues;
                GetAllValuesSeries(out allIdx, out allEstimatedValues);

                this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                if (allEstimatedValues.Length > 0)
                {
                    this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIdx, allEstimatedValues);
                    this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
                }
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
                this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);

                // set the y-axis
                var axisY = this.chart.ChartAreas[0].AxisY;
                axisY.Title = Content.ProblemData.TargetVariable;
                double min = double.MaxValue, max = double.MinValue;
                foreach (var point in chart.Series.SelectMany(x => x.Points))
                {
                    if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0]))
                    {
                        continue;
                    }
                    var y = point.YValues[0];
                    if (y < min)
                    {
                        min = y;
                    }
                    if (y > max)
                    {
                        max = y;
                    }
                }

                double axisMin, axisMax, axisInterval;
                ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
                axisY.Minimum  = axisMin;
                axisY.Maximum  = axisMax;
                axisY.Interval = axisInterval;

                UpdateCursorInterval();
                this.UpdateStripLines();
            }
        }
コード例 #4
0
        private void RedrawChart()
        {
            this.chart.Series.Clear();
            if (Content != null)
            {
                this.chart.ChartAreas[0].AxisX.Minimum = 0;
                this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.Dataset.Rows - 1;

                this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
                                                                                Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());
                // training series
                this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText            = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType             = SeriesChartType.FastLine;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndices.ToArray(), Content.EstimatedTrainingValues.ToArray());
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;
                // test series
                this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndices.ToArray(), Content.EstimatedTestValues.ToArray());
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;
                // series of remaining points
                int[]         allIndices         = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndices).Except(Content.ProblemData.TestIndices).ToArray();
                var           estimatedValues    = Content.EstimatedValues.ToArray();
                List <double> allEstimatedValues = allIndices.Select(index => estimatedValues[index]).ToList();
                this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                if (allEstimatedValues.Count > 0)
                {
                    this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndices, allEstimatedValues);
                    this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
                }
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;
                this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);

                // set the y-axis bounds
                var    axisY = this.chart.ChartAreas[0].AxisY;
                double min = double.MaxValue, max = double.MinValue;
                foreach (var point in chart.Series.SelectMany(x => x.Points))
                {
                    if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0]))
                    {
                        continue;
                    }
                    var y = point.YValues[0];
                    if (y < min)
                    {
                        min = y;
                    }
                    if (y > max)
                    {
                        max = y;
                    }
                }

                double axisMin, axisMax, axisInterval;
                ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
                axisY.Minimum  = axisMin;
                axisY.Maximum  = axisMax;
                axisY.Interval = axisInterval;

                UpdateCursorInterval();
                this.UpdateStripLines();
            }
        }
コード例 #5
0
        public static ScatterPlot CreateScatterPlot(IFilteredPreprocessingData preprocessingData, string variableNameX, string variableNameY, string variableNameGroup = "-", LegendOrder legendOrder = LegendOrder.Alphabetically)
        {
            ScatterPlot scatterPlot = new ScatterPlot();

            IList <double> xValues = preprocessingData.GetValues <double>(preprocessingData.GetColumnIndex(variableNameX));
            IList <double> yValues = preprocessingData.GetValues <double>(preprocessingData.GetColumnIndex(variableNameY));

            var points      = xValues.Zip(yValues, (x, y) => new Point2D <double>(x, y)).ToList();
            var validPoints = points.Where(p => !double.IsNaN(p.X) && !double.IsNaN(p.Y) && !double.IsInfinity(p.X) && !double.IsInfinity(p.Y)).ToList();

            if (validPoints.Any())
            {
                try {
                    double axisMin, axisMax, axisInterval;
                    ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.X), validPoints.Max(p => p.X), out axisMin, out axisMax, out axisInterval);
                    scatterPlot.VisualProperties.XAxisMinimumAuto       = false;
                    scatterPlot.VisualProperties.XAxisMaximumAuto       = false;
                    scatterPlot.VisualProperties.XAxisMinimumFixedValue = axisMin;
                    scatterPlot.VisualProperties.XAxisMaximumFixedValue = axisMax;
                } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
                try {
                    double axisMin, axisMax, axisInterval;
                    ChartUtil.CalculateOptimalAxisInterval(validPoints.Min(p => p.Y), validPoints.Max(p => p.Y), out axisMin, out axisMax, out axisInterval);
                    scatterPlot.VisualProperties.YAxisMinimumAuto       = false;
                    scatterPlot.VisualProperties.YAxisMaximumAuto       = false;
                    scatterPlot.VisualProperties.YAxisMinimumFixedValue = axisMin;
                    scatterPlot.VisualProperties.YAxisMaximumFixedValue = axisMax;
                } catch (ArgumentOutOfRangeException) { } // error during CalculateOptimalAxisInterval
            }


            //No Grouping
            if (string.IsNullOrEmpty(variableNameGroup) || variableNameGroup == "-")
            {
                ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", validPoints);
                scdr.VisualProperties.IsVisibleInLegend = false;
                scatterPlot.Rows.Add(scdr);
                return(scatterPlot);
            }

            //Grouping
            int groupVariableIndex = preprocessingData.GetColumnIndex(variableNameGroup);
            var groupingValues     = Enumerable.Empty <string>();

            if (preprocessingData.VariableHasType <double>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <double>(groupVariableIndex).Select(x => x.ToString());
            }
            else if (preprocessingData.VariableHasType <string>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <string>(groupVariableIndex);
            }
            else if (preprocessingData.VariableHasType <DateTime>(groupVariableIndex))
            {
                groupingValues = preprocessingData.GetValues <DateTime>(groupVariableIndex).Select(x => x.ToString());
            }
            var groups = groupingValues.Zip(validPoints, Tuple.Create).GroupBy(t => t.Item1, t => t.Item2);

            if (legendOrder == LegendOrder.Alphabetically)
            {
                groups = groups.OrderBy(x => x.Key, new NaturalStringComparer());
            }

            foreach (var group in groups)
            {
                var scdr = new ScatterPlotDataRow {
                    Name             = group.Key,
                    VisualProperties =
                    {
                        IsVisibleInLegend = true,
                        PointSize         = 6
                    }
                };
                scdr.Points.AddRange(group);
                scatterPlot.Rows.Add(scdr);
            }
            return(scatterPlot);
        }
コード例 #6
0
        private void RedrawChart()
        {
            this.chart.Series.Clear();
            if (Content != null)
            {
                this.chart.ChartAreas[0].AxisX.Minimum = 0;
                this.chart.ChartAreas[0].AxisX.Maximum = Content.ProblemData.Dataset.Rows - 1;

                // training series
                this.chart.Series.Add(ESTIMATEDVALUES_TRAINING_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].LegendText            = ESTIMATEDVALUES_TRAINING_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].ChartType             = SeriesChartType.Range;
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].EmptyPointStyle.Color = this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Color;
                var mean  = Content.EstimatedTrainingValues.ToArray();
                var s2    = Content.EstimatedTrainingVariances.ToArray();
                var lower = mean.Zip(s2, GetLowerConfBound).ToArray();
                var upper = mean.Zip(s2, GetUpperConfBound).ToArray();
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TrainingIndices.ToArray(), lower, upper);
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TRAINING_SERIES_NAME].Tag = Content;

                // test series
                this.chart.Series.Add(ESTIMATEDVALUES_TEST_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].LegendText = ESTIMATEDVALUES_TEST_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].ChartType  = SeriesChartType.Range;

                mean  = Content.EstimatedTestValues.ToArray();
                s2    = Content.EstimatedTestVariances.ToArray();
                lower = mean.Zip(s2, GetLowerConfBound).ToArray();
                upper = mean.Zip(s2, GetUpperConfBound).ToArray();
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Points.DataBindXY(Content.ProblemData.TestIndices.ToArray(), lower, upper);
                this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME]);
                this.chart.Series[ESTIMATEDVALUES_TEST_SERIES_NAME].Tag = Content;

                // series of remaining points
                int[] allIndices = Enumerable.Range(0, Content.ProblemData.Dataset.Rows).Except(Content.ProblemData.TrainingIndices).Except(Content.ProblemData.TestIndices).ToArray();
                mean  = Content.EstimatedValues.ToArray();
                s2    = Content.EstimatedVariances.ToArray();
                lower = mean.Zip(s2, GetLowerConfBound).ToArray();
                upper = mean.Zip(s2, GetUpperConfBound).ToArray();
                List <double> allLower = allIndices.Select(index => lower[index]).ToList();
                List <double> allUpper = allIndices.Select(index => upper[index]).ToList();
                this.chart.Series.Add(ESTIMATEDVALUES_ALL_SERIES_NAME);
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].LegendText = ESTIMATEDVALUES_ALL_SERIES_NAME;
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].ChartType  = SeriesChartType.Range;
                if (allIndices.Count() > 0)
                {
                    this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Points.DataBindXY(allIndices, allLower, allUpper);
                    this.InsertEmptyPoints(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);
                }
                this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME].Tag = Content;

                // target
                this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = TARGETVARIABLE_SERIES_NAME;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType  = SeriesChartType.FastLine;
                this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(Enumerable.Range(0, Content.ProblemData.Dataset.Rows).ToArray(),
                                                                                Content.ProblemData.Dataset.GetDoubleValues(Content.ProblemData.TargetVariable).ToArray());

                this.ToggleSeriesData(this.chart.Series[ESTIMATEDVALUES_ALL_SERIES_NAME]);


                // the series have been added in different order than in the normal line chart
                // --> adapt coloring;
                chart.ApplyPaletteColors();
                this.chart.Palette = ChartColorPalette.None;
                var s0Color = chart.Series[0].Color;
                var s1Color = chart.Series[1].Color;
                var s2Color = chart.Series[2].Color;
                var s3Color = chart.Series[3].Color;
                this.chart.PaletteCustomColors = new Color[] { s1Color, s2Color, s3Color, s0Color };

                // set the y-axis
                var axisY = this.chart.ChartAreas[0].AxisY;
                axisY.Title = Content.ProblemData.TargetVariable;
                double min = double.MaxValue, max = double.MinValue;
                foreach (var point in chart.Series.SelectMany(x => x.Points))
                {
                    if (!point.YValues.Any() || double.IsInfinity(point.YValues[0]) || double.IsNaN(point.YValues[0]))
                    {
                        continue;
                    }
                    var y = point.YValues[0];
                    if (y < min)
                    {
                        min = y;
                    }
                    if (y > max)
                    {
                        max = y;
                    }
                }

                double axisMin, axisMax, axisInterval;
                ChartUtil.CalculateOptimalAxisInterval(min, max, out axisMin, out axisMax, out axisInterval);
                axisY.Minimum  = axisMin;
                axisY.Maximum  = axisMax;
                axisY.Interval = axisInterval;

                UpdateCursorInterval();
                this.UpdateStripLines();
            }
        }