def backward_induction(ddp, T, v_term=None):
 n = ddp.num_states
 vs = np.empty(((T + 1), n))
 sigmas = np.empty((T, n), dtype=int)
 if (v_term is None):
  v_term = np.zeros(n)
 vs[T, :] = v_term
 for t in range(T, 0, (-1)):
  ddp.bellman_operator(vs[t, :], Tv=vs[(t - 1), :], sigma=sigmas[(t - 1), :])
 return (vs, sigmas)

def backward_induction ( ddp , T , v_term = None ) : n = ddp . num_states vs = np . empty ( ( ( T + 1 ) , n ) ) sigmas = np . empty ( ( T , n ) , dtype = int ) if ( v_term is None ) : v_term = np . zeros ( n ) vs [ T , : ] = v_term for t in range ( T , 0 , ( - 1 ) ) : ddp . bellman_operator ( vs [ t , : ] , Tv = vs [ ( t - 1 ) , : ] , sigma = sigmas [ ( t - 1 ) , : ] ) return ( vs , sigmas )
solve by backward induction a :math:t-period finite horizon discrete dynamic program with stationary reward and transition probability functions :math:r and :math:q and discount factor :math:beta in [0 .