Answers.Body: <p>Just try returning a function that takes the state as an input and returns the probabilities for each action in the form of a numpy array of length of the action space (set of possible actions). Here, is one attempt:</p>
  <pre><code>def EpsilonGreedyPolicy(Q, epsilon, no_of_actions):
  
      def policy(state): 
          probabilities = np.ones(no_of_actions, dtype = float) * 
                      epsilon / num_actions 
          best_action = np.argmax(Q[state]) 
          probabilities[best_action] += (1.0 - epsilon) 
          return probabilities 
     
      return policy
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-07-29T16:01:12.840Z
Answers.LastActivityDate: 2020-07-29T16:20:27.873Z
Answers.LastEditDate: 2020-07-29T16:20:27.873Z
Answers.UserDisplayName: Rithik Banerjee
Body: <p>I want to implement this function on a voice searching application:</p>
  <p><span class="math-container">$$
  Q(S, A) \leftarrow Q(S, A)+\alpha\left(R+\gamma Q\left(S^{\prime}, A^{\prime}\right)-Q(S, A)\right)
  $$</span></p>
  <p>And also restricted to use epsilon-greedy policy based on a given Q-function and epsilon. I simply need a <span class="math-container">$\epsilon$</span>-greedy policy for updating my q-table.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2020-07-29T16:00:15.287Z
Comments.Text: At-least show what have you tried?
Comments.UserDisplayName: Rithik Banerjee
Tags: <q-learning>
Title: How can I update my Q-table in Python?
UserDisplayName: mogoja
ThreadText: # How can I update my Q-table in Python?
  
  (Asked by: username_0 on 2020-07-29)
  
  I want to implement this function on a voice searching application:
  
  $$
  Q(S, A) \leftarrow Q(S, A)+\alpha\left(R+\gamma Q\left(S^{\prime}, A^{\prime}\right)-Q(S, A)\right)
  $$
  
  And also restricted to use epsilon-greedy policy based on a given Q-function and epsilon. I simply need a $\epsilon$-greedy policy for updating my q-table.
  
  **Tags:** q-learning
  
  > **Comments:**
  > **username_1**: At-least show what have you tried?  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-07-29. Score: 2 | Accepted answer
  
  Just try returning a function that takes the state as an input and returns the probabilities for each action in the form of a numpy array of length of the action space (set of possible actions). Here, is one attempt:
  
  ```
  def EpsilonGreedyPolicy(Q, epsilon, no_of_actions):
  
      def policy(state): 
          probabilities = np.ones(no_of_actions, dtype = float) * 
                      epsilon / num_actions 
          best_action = np.argmax(Q[state]) 
          probabilities[best_action] += (1.0 - epsilon) 
          return probabilities 
     
      return policy
  
  ```
  
  
  ---
  
  