In reinforcement learning with continuous state spaces, we often need to convert continuous states into feature vectors for use with linear function approximation. Coarse coding is a technique where the continuous state space is covered by a set of overlapping receptive fields (typically circles in 2D). For a given state, a binary feature vector is produced: each element is 1 if the state lies within (or on the boundary of) the corresponding receptive field, and 0 otherwise.
Implement a function coarse_coding that:
(x, y).(center_x, center_y, radius).(features, value) where:
features is a numpy array of integers (0s and 1s) indicating which receptive fields contain the state. A state is considered inside a receptive field if its Euclidean distance to the center is less than or equal to the radius.value is the dot product of features and weights (as a float) if weights are provided, otherwise None.This feature representation enables generalization: nearby states activate overlapping sets of features, while distant states activate disjoint features.