def etd_solution(P, G, L, X, ivec, r): # compute intermediate quantities (could be more efficient) di = mdputils.stationary(P) * ivec m = mult(resolvent(L, G, P.T), potential(G, P.T), di) M = np.diag(m) # solve the equation A = mult(X.T, M, potential(P, G, L), resolvent(P, G), X) A_inv = np.linalg.pinv(A) b = mult(X.T, M, potential(P, G, L), r) return np.array(np.dot(A_inv, b))
def td_solution(P, G, L, X, r): D = mdputils.distribution_matrix(P) A = mult(X.T, D, resolvent(P, G), X) A_inv = np.linalg.pinv(A) b = mult(X.T, D, r) return np.array(np.dot(A_inv, b))
def least_squares(P, G, X, r): """Compute the optimal weights via least squares.""" v = bellman(P, G, r) D = mdputils.distribution_matrix(P) return np.array(mult(np.linalg.pinv(mult(X.T, D, X)), X.T, D, v))