Can anyone help?
A basic algorithm for word prediction:
1-Assign each word in your library an integer, starting from 1. Suppose there are n such words in your library
2-Create M, a nxn matrix of zeros. If you want computational efficiency, you'll want a language/module that supports sparse matrices.
3-Calibrate the model with some sample text. Whenever word i is followed by word j, increase the value in row i and column j of M by 1.
And your model is calibrated!
Here are two ways to predict:
1-If we have word i and want to predict the next on, then let S be the sum of all the values in row i of M.
2-Generate a uniform random integer R between 1 and S.
3-Start summing the values in row i again, and as stop as soon as you reach R. The column that you stop in is the predicted word.
Alternatively:
1-Go through row i, keeping track of the highest value so far, H, and how many times it has occured, O.
2-Generate a uniform random integer between 1 and O, R.
3-Go through row i again, counting whenever you find a column with value H. When you reach the Rth such term, that column is the one you want.
Er, I kinda meant this as a counterexample to palsch's wall of text there.
You need to be more careful with your algebra of limits, there. The limit of a product of two functions is only the product of the limits if you can show that all the limits exist and are finite.