%% Create Policy Evaluation Function for PG Agent
% This example shows how to create a policy evaluation function for a PG Agent.
% First, create and train a reinforcement learning agent. For this example, load the PG agent trained in Train PG Agent to Balance Cart-Pole System:

load('MATLABCartpolePG.mat','agent')

% Then, create a policy evaluation function for this agent using default names:

generatePolicyFunction(agent);

% This command creates the evaluatePolicy.m file, which contains the policy function, and the agentData.mat file, which contains the trained deep neural network actor.
% View the generated function.

type evaluatePolicy.m

% For a given observation, the policy function evaluates a probability for each potential action using the actor network. Then, the policy function randomly selects an action based on these probabilities.
% Since the actor network for this PG agent has a single input layer and single output layer, you can generate code for this network using the Deep Learning Toolbox™ generation functionality. For more information, see Deploy Trained Policies.
% Copyright 2019 The MathWorks, Inc.