バージョン

相関データの例

CorrelationDataSample オブジェクトは xamDataChart コントロールのシリーズ データの相関機能のためのサンプル データを提供します。

Visual Basic の場合:

Imports System.Collections.ObjectModel
Namespace Infragistics.Samples.Data.Models
    Public Class CorrelationDataSample
        Inherits CorrelationDataCollection
        Public Sub New()
            _settings = New CorrelationDataSettings() With { _
                .DataPoints = 100, _
                .XMin = 0, _
                .YMin = 0 _
            }
            Me.Generate()
        End Sub
        #Region "Methods"
        Protected Sub Generate()
            Me.Clear()
            If Me.Settings.DataDistribution = DataDistribution.Random Then
                Me.GenerateRandomData()
            ElseIf Me.Settings.DataDistribution = DataDistribution.RandomlyIncreasing Then
                Me.GenerateRandomlyIncreasingData()
            ElseIf Me.Settings.DataDistribution = DataDistribution.RandomlyDecreasing Then
                Me.GenerateRandomlyDecreasingData()
            ElseIf Me.Settings.DataDistribution = DataDistribution.LinearlyIncreasing Then
                Me.GenerateLinearlyIncreasingData()
            ElseIf Me.Settings.DataDistribution = DataDistribution.LinearlyDecreasing Then
                Me.GenerateLinearlyDecreasingData()
            End If
        End Sub
        Protected Sub GenerateRandomData()
            Me.Clear()
            For i As Integer = 0 To Me.Settings.DataPoints - 1
                Dim x As Double = CorrelationDataGenerator.Random.[Next](Me.Settings.XMin, Me.Settings.XMax)
                Dim y As Double = CorrelationDataGenerator.Random.[Next](Me.Settings.YMin, Me.Settings.YMax)
                Me.Add(New CorrelationDataPoint() With { _
                    .X = x, _
                    .Y = y _
                })
            Next
        End Sub
        Protected Sub GenerateRandomlyIncreasingData()
            Me.Clear()
            Dim value As Integer = Me.Settings.YMin
            For i As Integer = 0 To Me.Settings.DataPoints - 1
                Dim change As Double = CorrelationDataGenerator.Random.NextDouble()
                If change > 0.5 Then
                    value += CInt(Math.Truncate(change * 20))
                Else
                    value -= CInt(Math.Truncate(change * 20))
                End If
                Dim x As Double = CorrelationDataGenerator.Random.[Next](i, i + Me.Settings.XRange)
                Dim y As Double = CorrelationDataGenerator.Random.[Next](value - Me.Settings.YRange, value + Me.Settings.YRange)
                Me.Add(New CorrelationDataPoint() With { _
                    .X = x, _
                    .Y = y _
                })
            Next
        End Sub
        Protected Sub GenerateRandomlyDecreasingData()
            Me.Clear()
            Dim value As Integer = Me.Settings.YMax
            For i As Integer = 0 To Me.Settings.DataPoints - 1
                Dim change As Double = CorrelationDataGenerator.Random.NextDouble()
                If change < 0.5 Then
                    value += CInt(Math.Truncate(change * 20))
                Else
                    value -= CInt(Math.Truncate(change * 20))
                End If
                Dim x As Double = CorrelationDataGenerator.Random.[Next](i, i + Me.Settings.XRange)
                Dim y As Double = CorrelationDataGenerator.Random.[Next](value - Me.Settings.YRange, value + Me.Settings.YRange)
                Me.Add(New CorrelationDataPoint() With { _
                    .X = x, _
                    .Y = y _
                })
            Next
        End Sub
        Protected Sub GenerateLinearlyIncreasingData()
            Me.Clear()
            Dim y As Double = Me.Settings.YMin
            For i As Integer = 0 To Me.Settings.DataPoints - 1
                Dim x As Double = i * Me.Settings.XInterval
                Me.Add(New CorrelationDataPoint() With { _
                    .X = x, _
                    .Y = y _
                })
                y += Me.Settings.YInterval
            Next
        End Sub
        Protected Sub GenerateLinearlyDecreasingData()
            Me.Clear()
            Dim y As Double = Me.Settings.YMax
            For i As Integer = 0 To Me.Settings.DataPoints - 1
                Dim x As Double = i * Me.Settings.XInterval
                Me.Add(New CorrelationDataPoint() With { _
                    .X = x, _
                    .Y = y _
                })
                y -= Me.Settings.YInterval
            Next
        End Sub
        #End Region
        #Region "Properties"
        Private _settings As CorrelationDataSettings
        Public Property Settings() As CorrelationDataSettings
            Get
                Return _settings
            End Get
            Set
                If _settings Is value Then
                    Return
                End If
                _settings = value
                Me.Generate()
            End Set
        End Property
        #End Region
    End Class
    Public Enum DataDistribution
        LinearlyIncreasing
        LinearlyDecreasing
        RandomlyIncreasing
        RandomlyDecreasing
        Random
    End Enum
    Public NotInheritable Class CorrelationDataGenerator
        Private Sub New()
        End Sub
        Public Shared Random As New Random()
    End Class
    Public Class CorrelationDataSettings
        Public Sub New()
            DataDistribution = DataDistribution.RandomlyIncreasing
            DataPoints = 100
            XMin = 5
            XInterval = 5
            XMax = 95
            XRange = 5
            YMin = 100
            YInterval = 5
            YMax = 900
            YRange = 150
        End Sub
        #Region "Properties"
        Public Property DataDistribution() As DataDistribution
            Get
                Return _DataDistribution
            End Get
            Set
                _DataDistribution = Value
            End Set
        End Property
        Private _DataDistribution As DataDistribution
        Public Property XInterval() As Double
            Get
                Return _XInterval
            End Get
            Set
                _XInterval = Value
            End Set
        End Property
        Private _XInterval As Double
        Public Property YInterval() As Double
            Get
                Return _YInterval
            End Get
            Set
                _YInterval = Value
            End Set
        End Property
        Private _YInterval As Double
        Public Property DataPoints() As Integer
            Get
                Return _DataPoints
            End Get
            Set
                _DataPoints = Value
            End Set
        End Property
        Private _DataPoints As Integer
        Public Property XMin() As Integer
            Get
                Return _XMin
            End Get
            Set
                _XMin = Value
            End Set
        End Property
        Private _XMin As Integer
        Public Property XMax() As Integer
            Get
                Return _XMax
            End Get
            Set
                _XMax = Value
            End Set
        End Property
        Private _XMax As Integer
        Public Property YMin() As Integer
            Get
                Return _YMin
            End Get
            Set
                _YMin = Value
            End Set
        End Property
        Private _YMin As Integer
        Public Property YMax() As Integer
            Get
                Return _YMax
            End Get
            Set
                _YMax = Value
            End Set
        End Property
        Private _YMax As Integer
        Public Property XRange() As Integer
            Get
                Return _XRange
            End Get
            Set
                _XRange = Value
            End Set
        End Property
        Private _XRange As Integer
        Public Property YRange() As Integer
            Get
                Return _YRange
            End Get
            Set
                _YRange = Value
            End Set
        End Property
        Private _YRange As Integer
        #End Region
    End Class
    Public Class CorrelationDataCollection
        Inherits ObservableCollection(Of CorrelationDataPoint)
    End Class
    Public Class CorrelationDataPoint
        #Region "Properties"
        Public Property X() As Double
            Get
                Return _X
            End Get
            Set
                _X = Value
            End Set
        End Property
        Private _X As Double
        Public Property Y() As Double
            Get
                Return _Y
            End Get
            Set
                _Y = Value
            End Set
        End Property
        Private _Y As Double
        #End Region
    End Class
End Namespace

C# の場合:

using System;
using System.Collections.ObjectModel;
namespace Infragistics.Samples.Data.Models
{
    public class CorrelationDataSample : CorrelationDataCollection
    {
        public CorrelationDataSample()
        {
            _settings = new CorrelationDataSettings
            {
                DataPoints = 100,
                XMin = 0,
                YMin = 0,
            };
            this.Generate();
        }
        #region Methods
        protected void Generate()
        {
            this.Clear();
            if (this.Settings.DataDistribution == DataDistribution.Random)
                this.GenerateRandomData();
            else if (this.Settings.DataDistribution == DataDistribution.RandomlyIncreasing)
                this.GenerateRandomlyIncreasingData();
            else if (this.Settings.DataDistribution == DataDistribution.RandomlyDecreasing)
                this.GenerateRandomlyDecreasingData();
            else if (this.Settings.DataDistribution == DataDistribution.LinearlyIncreasing)
                this.GenerateLinearlyIncreasingData();
            else if (this.Settings.DataDistribution == DataDistribution.LinearlyDecreasing)
                this.GenerateLinearlyDecreasingData();
        }
        protected void GenerateRandomData()
        {
            this.Clear();
            for (int i = 0; i < this.Settings.DataPoints; i++)
            {
                double x = CorrelationDataGenerator.Random.Next(this.Settings.XMin, this.Settings.XMax);
                double y = CorrelationDataGenerator.Random.Next(this.Settings.YMin, this.Settings.YMax);
                this.Add(new CorrelationDataPoint { X = x, Y = y });
            }
        }
        protected void GenerateRandomlyIncreasingData()
        {
            this.Clear();
            int value = this.Settings.YMin;
            for (int i = 0; i < this.Settings.DataPoints; i++)
            {
                double change = CorrelationDataGenerator.Random.NextDouble();
                if (change > .5)
                    value += (int)(change * 20);
                else
                    value -= (int)(change * 20);
                double x = CorrelationDataGenerator.Random.Next(i, i + this.Settings.XRange);
                double y = CorrelationDataGenerator.Random.Next(value - this.Settings.YRange, value + this.Settings.YRange);
                this.Add(new CorrelationDataPoint { X = x, Y = y });
            }
        }
        protected void GenerateRandomlyDecreasingData()
        {
            this.Clear();
            int value = this.Settings.YMax;
            for (int i = 0; i < this.Settings.DataPoints; i++)
            {
                double change = CorrelationDataGenerator.Random.NextDouble();
                if (change < .5)
                    value += (int)(change * 20);
                else
                    value -= (int)(change * 20);
                double x = CorrelationDataGenerator.Random.Next(i, i + this.Settings.XRange);
                double y = CorrelationDataGenerator.Random.Next(value - this.Settings.YRange, value + this.Settings.YRange);
                this.Add(new CorrelationDataPoint { X = x, Y = y });
            }
        }
        protected void GenerateLinearlyIncreasingData()
        {
            this.Clear();
            double y = this.Settings.YMin;
            for (int i = 0; i < this.Settings.DataPoints; i++)
            {
                double x = i * this.Settings.XInterval;
                this.Add(new CorrelationDataPoint { X = x, Y = y });
                y += this.Settings.YInterval;
            }
        }
        protected void GenerateLinearlyDecreasingData()
        {
            this.Clear();
            double y = this.Settings.YMax;
            for (int i = 0; i < this.Settings.DataPoints; i++)
            {
                double x = i * this.Settings.XInterval;
                this.Add(new CorrelationDataPoint { X = x, Y = y });
                y -= this.Settings.YInterval;
            }
        }
        #endregion
        #region Properties
        private CorrelationDataSettings _settings;
        public CorrelationDataSettings Settings
        {
            get { return _settings; }
            set
            {
                if (_settings == value) return;
                _settings = value;
                this.Generate();
            }
        }
        #endregion
    }
    public enum DataDistribution
    {
        LinearlyIncreasing,
        LinearlyDecreasing,
        RandomlyIncreasing,
        RandomlyDecreasing,
        Random,
    }
    public static class CorrelationDataGenerator
    {
        public static Random Random = new Random();
    }
    public class CorrelationDataSettings
    {
        public CorrelationDataSettings()
        {
            DataDistribution = DataDistribution.RandomlyIncreasing;
            DataPoints = 100;
            XMin = 5;
            XInterval = 5;
            XMax = 95;
            XRange = 5;
            YMin = 100;
            YInterval = 5;
            YMax = 900;
            YRange = 150;
        }
        #region Properties
        public DataDistribution DataDistribution { get; set; }
        public double XInterval { get; set; }
        public double YInterval { get; set; }
        public int DataPoints { get; set; }
        public int XMin { get; set; }
        public int XMax { get; set; }
        public int YMin { get; set; }
        public int YMax { get; set; }
        public int XRange { get; set; }
        public int YRange { get; set; }
        #endregion
    }
    public class CorrelationDataCollection : ObservableCollection<CorrelationDataPoint> { }
    public class CorrelationDataPoint
    {
        #region Properties
        public double X { get; set; }
        public double Y { get; set; }
        #endregion
    }
}