I am working on extended Raftery's model which is a more general higher-order Markov chain model, in that I need to solve the following Linear Programming model with certain constraints.
Following is the (link) Linear Programming function that needs to be minimized:
subject to :
Where vectors "W" and "λ" are to be solved in the equation.
Q and X are i-step transition probability matrix and steady-state probabilities respectively.
Below is the sample I am working with:
import numpy as np
one_step_array = np.array([[0.12, 0.75, 0.12],
[0.42, 0.14, 0.42],
[0.75, 0.25, 0.0]])
two_step_array = np.array([[0.43, 0.23, 0.33],
[0.43, 0.44, 0.11],
[0.20, 0.59, 0.20]])
steady_state = np.array([0.38, 0.39, 0.21])
Q_Arr = np.vstack((np.matmul(one_step_array,steady_state),np.matmul(two_step_array,steady_state))).transpose()
from pulp import *
w1 = LpVariable("w1",0,None)
w2 = LpVariable("w2",0,None)
w3 = LpVariable("W3",0, None)
L1 = LpVariable("L1",0,None)
L2 = LpVariable("L2",0,None)
prob = LpProblem("Problem",LpMinimize)
prob += w1 >= steady_state[0] - Q_Arr[0][0]*L1 - Q_Arr[0][1]*L2
prob += w1 >= -steady_state[0] + Q_Arr[0][0]*L1 + Q_Arr[0][1]*L2
prob += w2 >= steady_state[1] - Q_Arr[1][0]*L1 - Q_Arr[1][1]*L2
prob += w2 >= -steady_state[1] + Q_Arr[1][0]*L1 + Q_Arr[1][1]*L2
prob += w3 >= steady_state[2] - Q_Arr[2][0]*L1 - Q_Arr[2][1]*L2
prob += w3 >= -steady_state[2] + Q_Arr[2][0]*L1 + Q_Arr[2][1]*L2
prob += w1 >= 0
prob += w2 >= 0
prob += w3 >= 0
prob += L1 >= 0
prob += L2 >= 0
prob += L1 + L2 == 1
prob += w1+w2+w3
status = prob.solve(GLPK(msg=0))
LpStatus[status]
print (value(w1))
print (value(w2))
print (value(w3))
print (value(L1))
print (value(L2))
Result is (λ1,λ2,w1,w2,w3) = (1,0,0.051,0.027,0.14) instead of (1,0,0.028,0.0071,0.0214) which is not correct.
Could you please let me know where Am I going wrong?