Markov model definition process in Java

I am writing a helper learning algorithm in Java.

I ran into a math problem that I can probably solve, but since the processing will be difficult, I need an optimal solution.

Saying this, if someone knows an optimized library that will be absolutely awesome, but the language is Java, so you need to consider this.

The idea is pretty simple:

Objects will store a combination of variables such as ABDC, ACDE, DE, AE.

The maximum number of combinations will be based on how much I can run without slowing down the program, so theoretically we can say 100.

The decision process will generate one random variable per iteration. If the generated variable is part of one of the combinations, for example. "A", which is part of ABDC and ACDE, will increase the propensity for C and B (or any next letter in a stored combination).

To make things clearer, suppose that β€œA,” β€œB,” β€œC,” β€œD,” and β€œE” are the only possible variables. In truth, it will be more than 12 or 14, but this maximum will also depend on how much I can process without delay.

Since there are five possible variables, it will generate a weighted 1/5 random throw for the first iteration. If this roll turns out to be β€œA”, then at the next iteration β€œB” and β€œC” there will now be 2/5 inclinations instead of 1/5.

If the next iteration was to generate β€œB”, the propensity β€œD” would increase to 3/5. Note: the ratio is exponential; realistic, it will not be 1/5, but a slight increase, like 10%, that there will be a snowball, to say 50%, if it reaches the 4th variable in the sequence.

Now, in Java, I can probably achieve this functionality by tracking all saved combinations for each object. I thought that by distributing the tracking process in small steps at each iteration, it should not be too slow.

Another solution will display all possible combinations and their potential inclinations. This, of course, will simply require a search function, but it also presents problems when calculating all the features and storing somewhere, possibly in a file.

It has been suggested that I should use the Markov model and / or library, although I am not very good at this math.

How to quickly calculate this process in Java?
,

Example β†’>

Only one ABC sequence.

For three numbers, the odds start equal, so it will look something like rand (1,3)

If A is the result, we increase the probability of B because it is the next letter in the sequence. Let's say we doubled it.

So now the odds are: A = 1/4, C = 1/4, B = 2/4

The function will now look like rand (1,4), where results 3 and 4 represent option B.

If the next result is B, we want to increase the probability of C, because it is the next character in the sequence, but twice as much as the last time (exponentially).

Most likely, now something like: A = 1/6, C = 1/6, B = 4/6

Now the rand (1/6) function, where the values ​​3, 4, 5, 6 represent C.

+6
source share
1 answer

You can write a C / C ++ version if you want and use NDK (The overhead of NDK is in JNI translations from Java to C / C ++ methods, but after that they are much faster)

This is one idea. But ... I don’t think you need to go this far (at least get a version that works for small kits) (maybe moving to NDK later might be the best option for LARGE kits)

I think you would be much better off treating this as an array of "integer fractions", and ... a two-dimensional array for each set of action probabilities. The value of the numerators in the "top row" and the denominators in the "bottom row". Since the sets that you are going to work with are most likely small, I would think that a simple linked list of nodes, where each node has its own set of probabilities, would work. (These probabilities are transition tables from S to S 'from' that 'node.)

int[][] probs = new int[100][2]; 

So you can think of it as ...

1 2 1 1

4 3 4 9

like 1/4, 2/3, 1/4, 1/9 with all integer arithmetic. This would be simpler in "some" parts of the algorithm, because you can create nice helper functions for "removeColumn" (do 0/0 and skip the rest of the processing, etc. (Or, nevertheless, want to introduce it)) and 'adjustProbabilities ()'

(you can get away with one array of numerators if you make the denominators a single int (the lowest common denominator), but I would probably do this by optimization after getting the 2D version of the array)

Then simply write the 'simple' generic methods P, R, and V that interact with this data for each node. Then make them adjustable / extensible / etc with a good OO design.

Then simply β€œplay with numbers” for the discount factor, etc.

I think it’s more like β€œjust taking the time to test it,” and not a question of any really complicated mathematical algorithms, etc., because from what I see there are no β€œobvious” places for optimizing the kernel Algorithms

+1
source

All Articles