Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1512

Discrete Probability Detector in [VB6, VBA, JS]

$
0
0
These applications use an algorithm called DPD (Discrete Probability Detector) that transforms any sequence of symbols into a transition matrix. The algorithm may receive special characters from the entire ASCII range. These characters can be letters, numbers or special characters (ie. `7Eu9f$*"). The number of symbol/character types that make up a string, represent the number of states in a Markov chain. Thus, DPD is able to detect the number of states from the sequence and calculate the transition probabilities between these states. The final result of the algorithm is represented by a transition matrix (square matrix) which contains the transition probabilities between these symbol types (or states). The transition matrix can be further used for different prediction methods, such as Markov chains or Hidden Markov Models. This version of DPD is made in HTML/JavaScript/CSS, VB6, VBA (Excel).


Download: Discrete Probability Detector in [VB6, VBA, JS]


Name:  DPD.jpg
Views: 39
Size:  40.3 KB


Code:


Function Discrete_Probability_Detector(ByVal S As String)
 
 
    Dim e() As String

    Dim m() As String

    Dim l(0 To 1) As String
 
 
    k = Len(S)

    w = 1
 
 
    For i = 1 To k

        q = 1

        For j = 0 To Len(a)

            x = Mid(S, i, 1)

            y = Mid(a, j + 1, 1)

            If x = y Then q = 0

        Next j

        If q = 1 Then a = a & x

    Next i


    d = Len(a)

    ReDim e(w To d, 0 To 1) As String

    ReDim m(w To d, w To d) As String

 
    For i = w To d

        For j = w To d

          m(i, j) = 0

          If j = w Then

            e(i, 0) = Mid(a, i, 1)

            e(i, 1) = 0

          End If

        Next j

    Next i
 
 
    For i = 1 To k - 1

        l(0) = Mid(S, i, 1)

        l(1) = Mid(S, i + 1, 1)

        For j = w To d

            If l(0) = e(j, 0) Then

              e(j, 1) = Val(e(j, 1)) + 1

              r = j

            End If

            If l(1) = e(j, 0) Then c = j

        Next j

        m(r, c) = Val(m(r, c)) + 1

    Next i
 
 
    For i = w To d

        For j = w To d

            If Val(e(i, 1)) > 0 Then

                m(i, j) = Val(m(i, j)) / Val(e(i, 1))

            End If

        Next j

    Next i
 
 
End Function

Attached Images
 

Viewing all articles
Browse latest Browse all 1512

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>