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