pytorch的reinforce算法 官方文档

http://pytorch.org/docs/0.3.0/distributions.html

probs = policy_network(state)
m = Categorical(probs)
action = m.sample() # 抽样一个action
next_state, reward = env.step(action) # 得到一个reward
loss = -m.log_prob(action) * reward
loss.backward()