In reinforcement learning with continuous action spaces, a common approach is to parameterize the policy as a Gaussian (normal) distribution. The policy maps state features to a distribution over actions, from which actions can be sampled during exploration.
Implement a function gaussian_policy that computes the key quantities of a Gaussian policy for a single continuous action dimension:
The function takes:
state: a numpy array of shape (d,) representing state featuresmean_weights: a numpy array of shape (d,) representing the policy parametersstd: a positive float representing the fixed standard deviation of the policyaction: a float representing the action to evaluateReturn a dictionary with keys:
'mean': the policy mean (float, rounded to 4 decimal places)'pdf': the probability density at the action (float, rounded to 4 decimal places)'log_prob': the log-probability of the action (float, rounded to 4 decimal places)'score': the gradient of the log-probability with respect to mean_weights (list of floats, rounded to 4 decimal places)