(dynamics, policy, state_dim, steps, dt, reference='zero', const=1.0, ic=None)
return states, actions, times, r
Compute the closed-loop dynamic response to different reference signals.
Compute the closed-loop dynamic response to different reference signals.
Compute the closed - loop dynamic response to different reference signals .
def compute_closedloop_response(dynamics, policy, state_dim, steps, dt, reference='zero', const=1.0, ic=None):
    """Compute the closed-loop dynamic response to different reference signals."""
    action_dim = policy.output_dim

    if reference == 'impulse':
        r = np.zeros((steps + 1, action_dim))
        r[0, :] = (1 / dt) * np.ones((1, action_dim))
    elif reference == 'step':
        r = const*np.ones((steps + 1, action_dim))
    elif reference == 'zero':
        r = np.zeros((steps + 1, action_dim))

    times = dt*np.arange(steps + 1, dtype=NP_DTYPE).reshape((-1, 1))
    states = np.zeros((steps + 1, state_dim), dtype=NP_DTYPE)
    actions = np.zeros((steps + 1, action_dim), dtype=NP_DTYPE)
    if ic is not None:
        states[0, :] = np.asarray(ic, dtype=NP_DTYPE).reshape((1, state_dim))

    session = tf.get_default_session()
    with tf.name_scope('compute_closedloop_response'):
        current_ref = tf.placeholder(TF_DTYPE, shape=[1, action_dim])
        current_state = tf.placeholder(TF_DTYPE, shape=[1, state_dim])
        current_action = policy(current_state)
        next_state = dynamics(current_state, current_action + current_ref)
        data = [current_action, next_state]

    for i in range(steps):
        feed_dict = {current_ref: r[[i], :], current_state: states[[i], :]}
        actions[i, :], states[i + 1, :] = session.run(data, feed_dict)

    # Get the last action for completeness
    feed_dict = {current_ref: r[[-1], :], current_state: states[[-1], :]}
    actions[-1, :], _ = session.run(data, feed_dict)

    return states, actions, times, r
def compute_closedloop_response ( dynamics , policy , state_dim , steps , dt , reference = 'zero' , const = 1.0 , ic = None ) : action_dim = policy . output_dim if reference == 'impulse' : r = np . zeros ( ( steps + 1 , action_dim ) ) r [ 0 , : ] = ( 1 / dt ) * np . ones ( ( 1 , action_dim ) ) elif reference == 'step' : r = const * np . ones ( ( steps + 1 , action_dim ) ) elif reference == 'zero' : r = np . zeros ( ( steps + 1 , action_dim ) ) times = dt * np . arange ( steps + 1 , dtype = NP_DTYPE ) . reshape ( ( - 1 , 1 ) ) states = np . zeros ( ( steps + 1 , state_dim ) , dtype = NP_DTYPE ) actions = np . zeros ( ( steps + 1 , action_dim ) , dtype = NP_DTYPE ) if ic is not None : states [ 0 , : ] = np . asarray ( ic , dtype = NP_DTYPE ) . reshape ( ( 1 , state_dim ) ) session = tf . get_default_session ( ) with tf . name_scope ( 'compute_closedloop_response' ) : current_ref = tf . placeholder ( TF_DTYPE , shape = [ 1 , action_dim ] ) current_state = tf . placeholder ( TF_DTYPE , shape = [ 1 , state_dim ] ) current_action = policy ( current_state ) next_state = dynamics ( current_state , current_action + current_ref ) data = [ current_action , next_state ] for i in range ( steps ) : feed_dict = { current_ref : r [ [ i ] , : ] , current_state : states [ [ i ] , : ] } actions [ i , : ] , states [ i + 1 , : ] = session . run ( data , feed_dict ) # Get the last action for completeness feed_dict = { current_ref : r [ [ - 1 ] , : ] , current_state : states [ [ - 1 ] , : ] } actions [ - 1 , : ] , _ = session . run ( data , feed_dict ) return states , actions , times , r