Implement a function feature_density_approximation that demonstrates how the density of basis functions affects value function approximation quality in a continuous state space.
In reinforcement learning with continuous states, we often approximate the value function using a set of basis features. A common choice is Radial Basis Functions (RBFs), where each feature is a Gaussian centered at some point in state space. The number and placement of these centers -- the feature density -- directly impacts how well the approximation can capture the true value function.
Your function should:
Place n_centers RBF centers uniformly across the interval [0, 1]. If n_centers is 1, place the center at 0.5. Otherwise, use equally spaced points from 0.0 to 1.0 inclusive.
Compute RBF feature vectors for each state, where feature i is: phi_i(s) = exp(-(s - c_i)^2 / (2 * sigma^2))
Fit the weight vector by solving the least-squares problem to minimize the squared error between the linear combination of features and the training values.
Evaluate the fitted approximation on the test states and compute the Root Mean Squared Error (RMSE) between predictions and true test values.
Return a dictionary with keys: 'centers' (list of center positions), 'weights' (fitted weight vector), 'predictions' (predicted values at test states), and 'rmse' (the test RMSE). All values should be rounded to 4 decimal places.