Policy gradient का परिचय

Python में Deep Reinforcement Learning

Timothée Carayol

Principal Machine Learning Engineer, Komment

DRL में Policy मेथड्स का परिचय

 

Q-learning:

  • एक्शन वैल्यू फंक्शन Q सीखें

A Q-network, with the state as input and the action values as output

  • नीति: सबसे अधिक वैल्यू वाला एक्शन चुनें

 

Policy learning:

  • नीति सीधे सीखें

A policy network, with the state as input and the action probabilities as output

Python में Deep Reinforcement Learning

Policy learning

 

  • stochastic हो सकती है
  • continuous स्पेसेज़ संभालें
  • उद्देश्य को सीधे optimize करें
  • variance अधिक
  • sample efficiency कम

 

  • Deep-Q learning में: नीतियाँ deterministic होती हैं

 

$\pi_\theta(a_t | s_t)$:

  • state $s_t$ में $a_t$ के लिए probability distribution, जहाँ:
    • $a_t$, $s_t$: स्टेप $t$ पर एक्शन और स्टेट
    • $\theta$: policy पैरामीटर (नेटवर्क वेट्स)
Python में Deep Reinforcement Learning

Policy नेटवर्क (discrete actions)

class PolicyNetwork(nn.Module):
  def __init__(self, state_size, action_size):
    super(PolicyNetwork, self).__init__()
    self.fc1 = nn.Linear(state_size, 64)
    self.fc2 = nn.Linear(64, 64)
    self.fc3 = nn.Linear(64, action_size)

  def forward(self, state):
    x = torch.relu(self.fc1(torch.tensor(state)))
    x = torch.relu(self.fc2(x))
    action_probs = torch.softmax(self.fc3(x), dim=-1)
    return action_probs

action_probs = policy_network(state) print('Action probabilities:', action_probs)
Action probabilities: tensor([0.21, 0.02, 0.74, 0.03])

चार संभावित actions का इंडेक्स और probability दिखाती तालिका. 'up' का इंडेक्स 0 और probability 0.21; 'right' का 1 और 0.02; 'down' का 2 और 0.74; 'left' का 3 और 0.03.

action_dist = (
    torch.distributions.Categorical(action_probs))

action = action_dist.sample()
Python में Deep Reinforcement Learning

Objective फंक्शन

 

  • नीति को expected returns अधिकतम करने चाहिए

    • मानें एजेंट $\pi_\theta$ फॉलो करता है
    • policy पैरामीटर $\theta$ optimize करके
  • objective फंक्शन:

An equation: J(pi theta) = Expected value over trajectories tau following pi theta of R_tau, where R_tau is the episode return

 

  • $J$ को अधिकतम करने के लिए: $\theta$ के सापेक्ष gradient चाहिए:

Gradient of J(pi_theta) with respect to theta

Python में Deep Reinforcement Learning

Objective फंक्शन

 

  • नीति को expected returns अधिकतम करने चाहिए

    • मानें एजेंट $\pi_\theta$ फॉलो करता है
    • policy पैरामीटर $\theta$ optimize करके
  • objective फंक्शन:

The definition of J(pi theta), unchanged  from the previous slide

 

  • $J$ को अधिकतम करने के लिए: $\theta$ के सापेक्ष gradient चाहिए:

Gradient of J(pi_theta) with respect to theta is called the policy gradient

Python में Deep Reinforcement Learning

Policy gradient प्रमेय

 

  • $\nabla_\theta J(\pi_\theta)$ के लिए एक tractable अभिव्यक्ति देता है
  • $\pi_\theta$ फॉलो करती trajectories पर expectation
    • trajectories इकट्ठा करें और returns देखें

 

The policy gradient theorem: Gradient of J(pi_theta) with respect to theta equals the expectation over trajectories tau following pi_theta of...

Python में Deep Reinforcement Learning

Policy gradient प्रमेय

 

  • $\nabla_\theta J(\pi_\theta)$ के लिए एक tractable अभिव्यक्ति देता है
  • $\pi_\theta$ फॉलो करती trajectories पर expectation
    • trajectories इकट्ठा करें और returns देखें
  • हर trajectory के लिए: रिटर्न $R_\tau$ लें

 

The policy gradient theorem: Gradient of J(pi_theta) with respect to theta equals the expectation over trajectories tau following pi_theta of the episode return multiplied by...

Python में Deep Reinforcement Learning

Policy gradient प्रमेय

 

  • $\nabla_\theta J(\pi_\theta)$ के लिए एक tractable अभिव्यक्ति देता है
  • $\pi_\theta$ फॉलो करती trajectories पर expectation
    • trajectories इकट्ठा करें और returns देखें
  • हर trajectory के लिए: रिटर्न $R_\tau$ लें
  • चुने गए actions की log probabilities के gradients के योग से गुणा करें
  • समझ: 'अच्छे' एपिसोड में लिए गए सभी actions की probability बढ़ाने की दिशा में $\theta$ को हल्का धकेलें

 

The policy gradient theorem: Gradient of J(pi_theta) with respect to theta equals the expectation over trajectories tau following pi_theta of the episode return multiplied by the sum of the gradients of log action probabilities, summed over all actions in the trajectory.

Python में Deep Reinforcement Learning

 

Pong गेम दर्शाता एक gif

Python में Deep Reinforcement Learning

अभ्यास करते हैं!

Python में Deep Reinforcement Learning

Preparing Video For Download...