This webpage uses the Discrete Probability Detector algorithm. The purpose of this algorithm is to convert any text into a probability matrix.
Convert any string into a stochastic matrix: Markov Chains
The original publication of the algorithm:
Paul A. Gagniuc. Markov chains: from theory to implementation and experimentation. Hoboken, NJ, John Wiley & Sons, USA, 2017, ISBN: 978-1-119-38755-8.
The Discrete Probability Detector (DPD) algorithm implementation in javascript:
var s = "anything";
|--------------[ Phase one ]--------------| var x;
var y;
var a = "";
var k = s.length;
for(var i=0; i<=k; i++){
var q = 1;
for(var j=0; j<=a.length; j++){
x = s.substr(i, 1);
y = a.substr(j, 1);
if (x === y) {q = 0;}
}
if (q === 1) {a = a + x;}
}
|--------------[ Phase two ]--------------| var d = a.length;
var m = [];
var e = [];
var l = [];
for(var i=1; i<=d; i++){
m[i]=[];
e[i]=[];
for(var j=1; j<=d; j++){
m[i][j]=0;
if (j === 1) {
e[i][0]=a.substr(i-1, 1);
e[i][1]=0;
}
}
}
|-------------[ Phase three ]-------------|
l[0]="";
l[1]="";
for(var i=0; i<s.length-1; i++){
l[0] = s.substr(i, 1);
l[1] = s.substr(i + 1, 1);
for(var j=1; j<=d; j++){
if (l[0] === e[j][0]) {
e[j][1] = e[j][1] + 1;
r = j;
}
if (l[1] === e[j][0]) {c=j;}
}
m[r][c] = m[r][c] + 1;
}
|-------------[ Phase four ]--------------| for(var i=1; i<=d; i++){
for(var j=1; j<=d; j++){
if (e[i][1] > 0) {
m[i][j]=m[i][j]/e[i][1];
}
}
}
|----------------[ END ]------------------|