Question: # Part 3 : Succcess Rate Function In Part 4 , you will be frequently asked to use simulation to estimate an agent's success rate

# Part 3: Succcess Rate Function
In Part 4, you will be frequently asked to use simulation to estimate an agent's success rate under a given policy. To simplify this process, we will create a function to run such a simulation.
## 3.A - Define Function
Please define a function named `success_rate` with five parameters named `env`,`policy`,`episodes`,`max_steps`, and `random_state`. The function should perform the steps described below.
1. Set the NumPy random seed to `random_state`.
2. Create a variable called `goals`, setting it to 0.
3. Run a `for` loop for a number of iterations indicated by the `episodes` parameter. The loop should complete the following steps in each iteration:
* Generate an episode for the environment instance `env`, following the policy given by the `policy` parameter. To avoid infinite loops, set `max_steps=max_steps`.
* If the episode resulted in the agent finding the goal, increment `goals`.
4. After the loop completes, calculate and return the observed success rate for the agent.
## 3.B - Test Function
Test your function by calling it on the `FrozenPlatform` environment from Part 2 along with the opimal policy found for that environment using value iteration. Use 10,000 episodes, set `max_steps=200`, and set `random_state=1`.
Print the message below with the blank filled in with the appropriate value, rounded to 4 decimal places. If your function was implemented correctly, you should get a success rate of 0.4114.
When following the optimal policy, the agent's success rate was ____.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!