(dynamics, policy, initial_state, num_steps)
return states, actions
Compute a state trajectory given dynamics and a policy.

    Parameters
    ----------
    dynamics : callable
        A function that takes the current state and action as input and returns
        the next state.
    policy : callable
        A function that takes the current state as input and returns the
        action.
    initial_state : Tensor or ndarray
        The initial state at which to start simulating.
    num_steps : int
        The number of steps for which to simulate the system.

    Returns
    -------
    states : ndarray
        A (num_steps x state_dim) array with one state on each row.
    actions : ndarray
        A (num_steps x action_dim) array with the corresponding action on each
        row.
Compute a state trajectory given dynamics and a policy.
Compute a state trajectory given dynamics and a policy .
def compute_trajectory(dynamics, policy, initial_state, num_steps):
    """Compute a state trajectory given dynamics and a policy.

    Parameters
    ----------
    dynamics : callable
        A function that takes the current state and action as input and returns
        the next state.
    policy : callable
        A function that takes the current state as input and returns the
        action.
    initial_state : Tensor or ndarray
        The initial state at which to start simulating.
    num_steps : int
        The number of steps for which to simulate the system.

    Returns
    -------
    states : ndarray
        A (num_steps x state_dim) array with one state on each row.
    actions : ndarray
        A (num_steps x action_dim) array with the corresponding action on each
        row.
    """
    initial_state = np.atleast_2d(initial_state)
    state_dim = initial_state.shape[1]

    # Get storage (indexed by dynamics and policy)
    index = (dynamics, policy)
    storage = get_storage(_STORAGE, index=index)

    if storage is None:
        # Compute next state under the policy
        tf_state = tf.placeholder(config.dtype, [1, state_dim])
        tf_action = policy(tf_state)
        tf_next_state = dynamics(tf_state, tf_action)

        storage = [('tf_state', tf_state),
                   ('tf_action', tf_action),
                   ('tf_next_state', tf_next_state)]

        set_storage(_STORAGE, storage, index=index)
    else:
        tf_state, tf_action, tf_next_state = storage.values()

    # Initialize
    dtype = config.np_dtype
    states = np.empty((num_steps, state_dim), dtype=dtype)
    actions = np.empty((num_steps - 1, policy.output_dim), dtype=dtype)

    states[0, :] = initial_state

    # Get the feed dict
    session = tf.get_default_session()
    feed_dict = get_feed_dict(session.graph)

    next_data = [tf_next_state, tf_action]

    # Run simulation
    for i in range(num_steps - 1):
        feed_dict[tf_state] = states[[i], :]
        states[i + 1, :], actions[i, :] = session.run(next_data,
                                                      feed_dict=feed_dict)

    return states, actions
def compute_trajectory ( dynamics , policy , initial_state , num_steps ) : initial_state = np . atleast_2d ( initial_state ) state_dim = initial_state . shape [ 1 ] # Get storage (indexed by dynamics and policy) index = ( dynamics , policy ) storage = get_storage ( _STORAGE , index = index ) if storage is None : # Compute next state under the policy tf_state = tf . placeholder ( config . dtype , [ 1 , state_dim ] ) tf_action = policy ( tf_state ) tf_next_state = dynamics ( tf_state , tf_action ) storage = [ ( 'tf_state' , tf_state ) , ( 'tf_action' , tf_action ) , ( 'tf_next_state' , tf_next_state ) ] set_storage ( _STORAGE , storage , index = index ) else : tf_state , tf_action , tf_next_state = storage . values ( ) # Initialize dtype = config . np_dtype states = np . empty ( ( num_steps , state_dim ) , dtype = dtype ) actions = np . empty ( ( num_steps - 1 , policy . output_dim ) , dtype = dtype ) states [ 0 , : ] = initial_state # Get the feed dict session = tf . get_default_session ( ) feed_dict = get_feed_dict ( session . graph ) next_data = [ tf_next_state , tf_action ] # Run simulation for i in range ( num_steps - 1 ) : feed_dict [ tf_state ] = states [ [ i ] , : ] states [ i + 1 , : ] , actions [ i , : ] = session . run ( next_data , feed_dict = feed_dict ) return states , actions