function action1 = evaluatePolicy(observation1, actionSet)
%#codegen

% Reinforcement Learning Toolbox
% Generated on: 24-Jun-2021 11:34:24

% Select action from sampled probabilities
probabilities = localEvaluate(observation1);
% Normalize the probabilities
p = probabilities(:)'/sum(probabilities);
% Determine which action to take
edges = min([0 cumsum(p)],1);
edges(end) = 1;
[~,actionIndex] = histc(rand(1,1),edges); %#ok<HISTC>
action1 = actionSet(actionIndex);
end
%% Local Functions
function probabilities = localEvaluate(observation1)
persistent policy
if isempty(policy)
	policy = coder.loadDeepLearningNetwork('agentData.mat','policy');
end
observation1 = observation1(:);
observation1 = dlarray(single(observation1),'CB');
probabilities = predict(policy,observation1);
probabilities = extractdata(probabilities);
end