S - state typeI - intensity typepublic class MarkovCorrelation<S,I extends Number> extends Object
Copyright (c) 2013-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
BSD-style license. See OpenTrafficSim License.
| Constructor and Description |
|---|
MarkovCorrelation() |
| Modifier and Type | Method and Description |
|---|---|
void |
addState(S state,
double correlation)
Adds a state to the root group of the Markov Chain.
|
void |
addState(S superState,
S state,
double correlation)
Adds a state to the group of the Markov Chain indicated by a super state.
|
S |
drawState(S previousState,
S[] states,
I[] steadyState,
StreamInterface stream)
Draws a next state from this Markov Chain process, with predefined state correlations, but dynamic intensities.
|
String |
toString() |
public void addState(S state, double correlation)
p_ii = ss_i + (1 - ss_i) * c_i {eq. 1}
where,
p_ii: the probability state i returns after state i ss_i: the steady-state (overall mean) probability of state i c_i: correlation of state iEffective correlations of states depend on correlations of other states as well, so the given correlation is not guaranteed to result. One can easily see this from a system with 2 states: A and B. Suppose B has correlation. In order to maintain the same overall steady-state (occurrence proportion of A and B), it follows that state A also must be seen more frequently to follow itself.
not correlated: A B B A A A B A A A B A A B B very correlated: A A A A A A A A A B B B B B B (all B's grouped together, hence all A's grouped together and correlated)The effective correlation c_i of any state i can be calculated by reversing equation
eq. 1 using
for p_ii the effective value after all correlations are applied. The procedure to derive the various probabilities
from state i to state j (p_ij) is explained below. The procedure is based on the transition matrix
T, in which each value gives the probability that the state changes from i (the row) to state j (the
column). Consequently, the values in each row must sum to 1, as each state will be followed by another state.
| p_11 p_12 p_13 | | 0.70 0.20 0.10 |
T = | p_21 p_22 p_23 | = | 0.70 0.20 0.10 |
| p_31 p_32 p_33 | | 0.70 0.20 0.10 |
Our steady-state results as for whatever the previous state was, the steady-state probabilities are applied. Now suppose
that state C has a correlation of 0.4. This would give that p_33 := p_33 + (1 - p_33) * c
= 0.46. With this increased value, the probabilities of row 3 no longer add up to 1. Hence, p_31 and
p_32 should be reduced. However, we require that the same steady-state S is maintained. This will remain
the case for as long as T remains a reversible Markov Chain. This means that each state has as much input
probability, as it has output probability. A matrix where, except for the values on the diagonal, all column values are
equal, is reversible. So the base T without correlation is reversible, and we only need to maintain reversibility.
A method to maintain reversibility is to scale symmetric pairs. Hence, if we reduce p_32, we should reduce
p_23 by the same factor. Forcing row 3 to sum to 1, and scaling p_31, p_13, p_32 and
p_23 by the same factor 0.6 we obtain the third matrix below.
| 0.70 0.20 0.10 | | 0.70 0.20 0.10 | | 0.70 0.20 0.06 | | 0.74 0.20 0.06 |
T => | 0.70 0.20 0.10 | => | 0.70 0.20 0.10 | => | 0.70 0.20 0.06 | => | 0.70 0.24 0.06 |
| 0.70 0.20 0.10 | | 0.70 0.20 0.46 | | 0.42 0.12 0.46 | | 0.42 0.12 0.46 |
As we reduce p_13 and p_23, we also reduce the probability sums of rows 1 and 2. These reductions can be
compensated by increasing the values on the diagonals, as is done in the fourth matrix. Note that changing the diagonal
values does not affect reversibility. For example, 0.7*0.74 + 0.2*0.70 + 0.1*0.42 = 0.7 for the first column.eq. 1.state - S; statecorrelation - double; correlationIllegalArgumentException - if correlation is not within the range (-1 ... 1), or the state is already definedNullPointerException - if state is nullpublic void addState(S superState, S state, double correlation)
s_1 s_2 s_3 s_1 S_2 s_3
s_1 | p_11 p_12 p_13 | s_1 | p_11 p_12 p_13 |
s_2 | p_21 p_22 p_23 | => S_2 | p_21 p_22 p_23 |
s_3 | p_31 p_32 p_33 | s_3 | p_31 p_32 p_33 |
From the level of this matrix, nothing changes. Whenever the prior state was any of those inside S_2, row 2 is
applied to determine the next state. If the next state is matrix S_2, the state is further specified by
S_2. Matrix S_2 itself will be:
s_2 s_4
s_2 | p_22' p_24 |
s_4 | p_42 p_44 |
It will thus result in either state s_2 or state s_4. More states can now be added to S_2, using the
same super state s_2. In case the prior state was either s_1 or s_3, i.e. no state included in the
sub-group, the matrix of the sub-group defaults to fractions based on the steady-state only. Correlations are then also
ignored.getState().superState - S; state of groupstate - S; state to addcorrelation - double; correlationIllegalArgumentException - if correlation is not within the range (0 ... 1), the state is already defined, or
superState is not yet a stateNullPointerException - if an input is nullpublic S drawState(S previousState, S[] states, I[] steadyState, StreamInterface stream)
previousState - S; previous statestates - S[]; set of states to considersteadyState - I[]; current steady-state intensities of the statesstream - StreamInterface; to draw random numbersIllegalArgumentException - if number of states is not the same as the stead-state lengthNullPointerException - if states, steadyState or stream is nullCopyright © 2014–2019 Delft University of Technology. All rights reserved.