コード例 #1
0
        private void CalculateRegression()
        {
            var x = Vector.Create(ChartValues.Select(v => v.NDouble).ToArray());
            var y = Vector.Create(ChartValues.Select(v => v.TotDouble).ToArray());

            _regression = new SimpleRegressionModel(y, x);
            _regression.Fit();

            UpperValues.Clear();
            LowerValues.Clear();
            RegressionValues.Clear();
            NToNValues.Clear();
            XAxis.Clear();
            YAxis.Clear();

            var max = ChartValues.Max(p => p.NDouble);

            XAxis.Add(new ObservablePoint(0, 0));
            XAxis.Add(new ObservablePoint(0, max));
            YAxis.Add(new ObservablePoint(0, 0));
            YAxis.Add(new ObservablePoint(max, 0));



            NToNValues.Add(new ObservablePoint(0, 0));
            NToNValues.Add(new ObservablePoint(max, max));

            var ci = _regression.GetPredictionInterval(0, .99);

            UpperValues.Add(new ObservablePoint(0, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(0, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(0, ci.Center));

            ci = _regression.GetPredictionInterval(max, .99);
            UpperValues.Add(new ObservablePoint(max, ci.UpperBound));
            LowerValues.Add(new ObservablePoint(max, ci.LowerBound));
            RegressionValues.Add(new ObservablePoint(max, ci.Center));

            var above = 0.0;
            var below = 0.0;

            foreach (var point in ChartValues)
            {
                var interval = _regression.GetPredictionInterval(point.NDouble, .99);
                if (point.TotDouble <= interval.UpperBound && point.TotDouble > interval.Center)
                {
                    above++;
                }
                else if (point.TotDouble <= interval.Center && point.TotDouble >= interval.LowerBound)
                {
                    below++;
                }
            }
            Console.WriteLine("Above Center: " + above / ChartValues.Count);
            Console.WriteLine("Below Center: " + below / ChartValues.Count);
        }
コード例 #2
0
        public SingleKeySizeForm(int size, IEnumerable <XY> points)
        {
            InitializeComponent();
            _size = size;

            var mapper = Mappers.Xy <XY>()
                         .X(model => model.NDouble)
                         .Y(model => model.TotDouble)
                         .Fill(model => model.Y >= ChartValues.GroupBy(p => p.Y)
                               .OrderByDescending(gp => gp.Count()).Select(p => p.Key).FirstOrDefault()
                    ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 150, 0))
                    : model.Y < ChartValues.GroupBy(p => p.Y)
                               .OrderByDescending(gp => gp.Count()).Select(p => p.Key).FirstOrDefault()
                    ? new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                    : null);

            Charting.For <XY>(mapper);

            ChartValues        = new ChartValues <XY>();
            RegressionValues   = new ChartValues <ObservablePoint>();
            UpperValues        = new ChartValues <ObservablePoint>();
            LowerValues        = new ChartValues <ObservablePoint>();
            NToNValues         = new ChartValues <ObservablePoint>();
            XAxis              = new ChartValues <ObservablePoint>();
            YAxis              = new ChartValues <ObservablePoint>();
            versusChart.Series = new SeriesCollection
            {
                new ScatterSeries
                {
                    Values        = ChartValues,
                    PointGeometry = DefaultGeometries.Diamond
                },
                new LineSeries
                {
                    Values        = RegressionValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = UpperValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = LowerValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(200, 0, 0))
                },
                new LineSeries
                {
                    Values        = NToNValues,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 200))
                },
                new LineSeries
                {
                    Values        = XAxis,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0))
                },
                new LineSeries
                {
                    Values        = YAxis,
                    PointGeometry = null,
                    Fill          = Brushes.Transparent,
                    Stroke        = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0))
                }
            };
            versusChart.DataClick += (sender, point) =>
            {
                var valuePoint = ChartValues.FirstOrDefault(v => v.NDouble == point.X && v.TotDouble == point.Y);
                if (valuePoint != null)
                {
                    Console.WriteLine(valuePoint.ToString());
                    Console.WriteLine("Range: " + _regression.GetPredictionInterval(valuePoint.NDouble, .99));
                }
            };
            versusChart.Zoom = ZoomingOptions.Xy;
            versusChart.DisableAnimations = true;
            versusChart.DataTooltip       = null;
            ChartValues.AddRange(points);

            CalculateRegression();

            graphTabPanel.SelectedIndexChanged += (sender, args) =>
            {
                if (graphTabPanel.SelectedIndex == 1)
                {
                    BuildHistogram();
                }
            };

            Timer = new Timer
            {
                Interval = 10000
            };
            Timer.Tick += (sender, args) => addButton.PerformClick();
        }