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))