(grid, closed_loop_dynamics, horizon=100, tol=1e-3, equilibrium=None, no_traj=True)
Compute the largest ROA as a set of states in a discretization.
Compute the largest ROA as a set of states in a discretization.
Compute the largest ROA as a set of states in a discretization .
def compute_roa(grid, closed_loop_dynamics, horizon=100, tol=1e-3, equilibrium=None, no_traj=True):
    """Compute the largest ROA as a set of states in a discretization."""
    if isinstance(grid, np.ndarray):
        all_points = grid
        nindex = grid.shape[0]
        ndim = grid.shape[1]
    else: # grid is a GridWorld instance
        all_points = grid.all_points
        nindex = grid.nindex
        ndim = grid.ndim

    # Forward-simulate all trajectories from initial points in the discretization
    if no_traj:
        end_states = all_points
        for t in range(1, horizon):
            end_states = closed_loop_dynamics(end_states)
    else:
        trajectories = np.empty((nindex, ndim, horizon))
        trajectories[:, :, 0] = all_points
        for t in range(1, horizon):
            trajectories[:, :, t] = closed_loop_dynamics(trajectories[:, :, t - 1])
        end_states = trajectories[:, :, -1]

    if equilibrium is None:
        equilibrium = np.zeros((1, ndim))

    # Compute an approximate ROA as all states that end up "close" to 0
    dists = np.linalg.norm(end_states - equilibrium, ord=2, axis=1, keepdims=True).ravel()
    roa = (dists <= tol)
    if no_traj:
        return roa
    else:
        return roa, trajectories
def compute_roa ( grid , closed_loop_dynamics , horizon = 100 , tol = 1e-3 , equilibrium = None , no_traj = True ) : if isinstance ( grid , np . ndarray ) : all_points = grid nindex = grid . shape [ 0 ] ndim = grid . shape [ 1 ] else : # grid is a GridWorld instance all_points = grid . all_points nindex = grid . nindex ndim = grid . ndim # Forward-simulate all trajectories from initial points in the discretization if no_traj : end_states = all_points for t in range ( 1 , horizon ) : end_states = closed_loop_dynamics ( end_states ) else : trajectories = np . empty ( ( nindex , ndim , horizon ) ) trajectories [ : , : , 0 ] = all_points for t in range ( 1 , horizon ) : trajectories [ : , : , t ] = closed_loop_dynamics ( trajectories [ : , : , t - 1 ] ) end_states = trajectories [ : , : , - 1 ] if equilibrium is None : equilibrium = np . zeros ( ( 1 , ndim ) ) # Compute an approximate ROA as all states that end up "close" to 0 dists = np . linalg . norm ( end_states - equilibrium , ord = 2 , axis = 1 , keepdims = True ) . ravel ( ) roa = ( dists <= tol ) if no_traj : return roa else : return roa , trajectories