Artificial Intelligence, Data Science, Machine Learning, Reinforcement Learning, Programming.
with tf.GradientTape() as tape: # Get the action probabilities from the policy network action_probs = policy_network(states) # Calculate the loss loss = tf.cast(tf.math.log(tf.gather(action_probs,actions,axis=1,batch_dims=1)),tf.float64) loss = loss * discounted_rewards loss = -tf.reduce_sum(loss)