Answers.Body: <p>I am confused. For the initial <span class="math-container">$Q$</span>-values, you generate one for each possible row <span class="math-container">$(1, 0, 0), (0,0,0), \ldots$</span> so you would have 4 states.</p>
  <p>However, from the first paragraph it seems that the states themselves are matrices (one row for each user), so the state space is a set of such matrices.</p>
  <p>That means that your <span class="math-container">$Q$</span>-table should have a row for each possible matrix, and a column for each possible total assignment of items to users.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-21T16:17:51.977Z
Answers.Text: So, suppose we have Q-table accessed as follows: Q[state, action]. So the state is the whole state space matrix and the action is the whole matrix with the different actions for each resource and user ?
Answers.UserDisplayName: Ness
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-21T16:20:36.977Z
Answers.Text: I am confused too because from what I gathered from the examples online, is that if we have a state space that's an array of different positions (for example) that the agent can be in, then the state in the Q-table would be each position in that state space. So what I thought I should do is represent each row in the state space as a key for the Q-table.
Answers.UserDisplayName: Ness
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-21T16:25:54.783Z
Answers.Text: A state should be the full description of the state. The state space is the set of all possible such states. It appears that in your example, a state is a matrix (with one row for each current user). The state space is a set of such matrices.
  
  In the online examples, each state is just a single position, so there the table is a bit easier.
Answers.UserDisplayName: Robby Goetschalckx
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-10-21T16:07:20.383Z
Answers.LastActivityDate: 2020-10-21T16:07:20.383Z
Answers.UserDisplayName: Robby Goetschalckx
Body: <p>I have created my own RL environment where I have a 2-dimensional matrix as a state space, the rows represent the users that are asking for a service, and 3 columns representing 3 types of users; so if a user U0 is of type 1 is asking for a service, then the first row would be (0, 1, 0) (first column is type 0, second is type 1...).</p>
  <p>The state space values are randomly generated each episode.</p>
  <p>I also have an action space, representing which resources were allocated to which users.
  The action space is a 2-dimensional matrix, the rows being the resources that the agent has, and the columns represent the users. So, suppose we have 5 users and 6 resources, if user 1 was allocated resource 2, then the 3rd line would be like this: ('Z': a value zero was chosen, 'O': a value one was chosen)
  (Z, O, Z, Z, Z)</p>
  <p>The possible actions are a list of tuples, the length of the list is equal to the number of users + 1, and the length of each tuple is equal to the number of users.
  Each tuple has one column set to 'O', and the rest to 'Z'. (Each resource can be allocated to one user only). So the number of the tuples that have one column = 'O', is equal to the number of users, and then there is one tuple that has all columns set to 'Z', which means that the resource was not allocated to any users.</p>
  <p>Now, when the agent chooses the action, for the first resource it picks an action from the full list of possible action, then for the second resource, the action previously chosen is removed from the possible actions, so it chooses from the actions left, and so on and so forth; and that's because each user can be allocated one resource only. The action tuple with all 'Z' can always be chosen.</p>
  <p>When the agent allocates a resource to a user that didn't request a service, a penalty is given (varies with the number of users that didn't ask for a service but were allocated a resource), otherwise, a reward is given (also varies depending on the number of users that were satisfied).</p>
  <p>The problem is, the agent always tends to pick the same actions, and those actions are the tuple with all 'Z' for all the users. I tried to play with the q_values initial values; q_values is a dictionary with 2 keys: 1st key: the state being a tuple representing each possible state from the state space, meaning (0, 0, 0) &amp; (1, 0, 0) &amp; (0, 1, 0) &amp; (0, 0, 1), combined with each action from the possible actions list.
  I also tried different learning_rate values, different penalties and rewards etc. But it always does the same thing.</p>
  <p><a href="https://i.sstatic.net/5sLZb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5sLZb.png" alt="enter image description here" /></a>
  <a href="https://i.sstatic.net/MbxCV.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/MbxCV.png" alt="enter image description here" /></a></p>
  
Tags: <reinforcement-learning><python><q-learning>
Title: Q-learning agent stuck at taking same actions
UserDisplayName: Ness
ThreadText: # Q-learning agent stuck at taking same actions
  
  (Asked by: username_0 on 2020-10-21)
  
  I have created my own RL environment where I have a 2-dimensional matrix as a state space, the rows represent the users that are asking for a service, and 3 columns representing 3 types of users; so if a user U0 is of type 1 is asking for a service, then the first row would be (0, 1, 0) (first column is type 0, second is type 1...).
  
  The state space values are randomly generated each episode.
  
  I also have an action space, representing which resources were allocated to which users.
  The action space is a 2-dimensional matrix, the rows being the resources that the agent has, and the columns represent the users. So, suppose we have 5 users and 6 resources, if user 1 was allocated resource 2, then the 3rd line would be like this: ('Z': a value zero was chosen, 'O': a value one was chosen)
  (Z, O, Z, Z, Z)
  
  The possible actions are a list of tuples, the length of the list is equal to the number of users + 1, and the length of each tuple is equal to the number of users.
  Each tuple has one column set to 'O', and the rest to 'Z'. (Each resource can be allocated to one user only). So the number of the tuples that have one column = 'O', is equal to the number of users, and then there is one tuple that has all columns set to 'Z', which means that the resource was not allocated to any users.
  
  Now, when the agent chooses the action, for the first resource it picks an action from the full list of possible action, then for the second resource, the action previously chosen is removed from the possible actions, so it chooses from the actions left, and so on and so forth; and that's because each user can be allocated one resource only. The action tuple with all 'Z' can always be chosen.
  
  When the agent allocates a resource to a user that didn't request a service, a penalty is given (varies with the number of users that didn't ask for a service but were allocated a resource), otherwise, a reward is given (also varies depending on the number of users that were satisfied).
  
  The problem is, the agent always tends to pick the same actions, and those actions are the tuple with all 'Z' for all the users. I tried to play with the q\_values initial values; q\_values is a dictionary with 2 keys: 1st key: the state being a tuple representing each possible state from the state space, meaning (0, 0, 0) & (1, 0, 0) & (0, 1, 0) & (0, 0, 1), combined with each action from the possible actions list.
  I also tried different learning\_rate values, different penalties and rewards etc. But it always does the same thing.
  
  [![enter image description here](https://i.sstatic.net/5sLZb.png)](https://i.sstatic.net/5sLZb.png)
  [![enter image description here](https://i.sstatic.net/MbxCV.png)](https://i.sstatic.net/MbxCV.png)
  
  **Tags:** reinforcement-learning, python, q-learning
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2020-10-21. Score: 1 | Accepted answer
  
  I am confused. For the initial $Q$-values, you generate one for each possible row $(1, 0, 0), (0,0,0), \ldots$ so you would have 4 states.
  
  However, from the first paragraph it seems that the states themselves are matrices (one row for each user), so the state space is a set of such matrices.
  
  That means that your $Q$-table should have a row for each possible matrix, and a column for each possible total assignment of items to users.
  
  > **Comments:**
  > **username_0**: So, suppose we have Q-table accessed as follows: Q[state, action]. So the state is the whole state space matrix and the action is the whole matrix with the different actions for each resource and user ?  
  > **username_0**: I am confused too because from what I gathered from the examples online, is that if we have a state space that's an array of different positions (for example) that the agent can be in, then the state in the Q-table would be each position in that state space. So what I thought I should do is represent each row in the state space as a key for the Q-table.  
  > **username_1**: A state should be the full description of the state. The state space is the set of all possible such states. It appears that in your example, a state is a matrix (with one row for each current user). The state space is a set of such matrices.  In the online examples, each state is just a single position, so there the table is a bit easier.  
  
  ---
  
  