pomdp
Model
Bases: Model
POMDP Model class. Partially Observable Markov Decision Process Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
states
|
int or list[str] or list[list[str]]
|
A list of state labels or an amount of states to be used. Also allows to provide a matrix of states to define a grid model. |
required |
actions
|
int or list
|
A list of action labels or an amount of actions to be used. |
required |
observations
|
int or list
|
A list of observation labels or an amount of observations to be used |
required |
transitions
|
array - like or function
|
The transitions between states, an array can be provided and has to be |S| x |A| x |S| or a function can be provided. If a function is provided, it has be able to deal with np.array arguments. If none is provided, it will be randomly generated. |
None
|
reachable_states
|
array - like
|
A list of states that can be reached from each state and actions. It must be a matrix of size |S| x |A| x |R| where |R| is the max amount of states reachable from any given state and action pair. It is optional but useful for speedup purposes. |
None
|
rewards
|
array - like or function
|
The reward matrix, has to be |S| x |A| x |S|. A function can also be provided here but it has to be able to deal with np.array arguments. If provided, it will be use in combination with the transition matrix to fill to expected rewards. |
None
|
observation_table
|
array - like or function
|
The observation matrix, has to be |S| x |A| x |O|. If none is provided, it will be randomly generated. |
None
|
rewards_are_probabilistic
|
bool
|
Whether the rewards provided are probabilistic or pure rewards. If probabilist 0 or 1 will be the reward with a certain probability. |
False
|
state_grid
|
array - like
|
If provided, the model will be converted to a grid model. |
None
|
start_probabilities
|
list
|
The distribution of chances to start in each state. If not provided, there will be an uniform chance for each state. It is also used to represent a belief of complete uncertainty. |
None
|
end_states
|
list
|
Entering either state in the list during a simulation will end the simulation. |
[]
|
end_actions
|
list
|
Playing action of the list during a simulation will end the simulation. |
[]
|
print_debug
|
bool
|
Whether to print debug logs about the creation progress of the POMDP Model. |
False
|
seed
|
int
|
For reproducible randomness. |
12131415
|
Attributes:
Name | Type | Description |
---|---|---|
states |
ndarray
|
A 1D array of states indices. Used to loop over states. |
state_labels |
list[str]
|
A list of state labels. (To be mainly used for plotting) |
state_count |
int
|
How many states are in the Model. |
state_grid |
ndarray
|
The state indices organized as a 2D grid. (Used for plotting purposes) |
actions |
ndarry
|
A 1D array of action indices. Used to loop over actions. |
action_labels |
list[str]
|
A list of action labels. (To be mainly used for plotting) |
action_count |
int
|
How many action are in the Model. |
observations |
ndarray
|
A 1D array of observation indices. Used to loop over obervations. |
observation_labels |
list[str]
|
A list of observation labels. (To be mainly used for plotting) |
observation_count |
int
|
How many observations can be made in the Model. |
transition_table |
ndarray
|
A 3D matrix of the transition probabilities. Can be None in the case a transition function is provided instead. Note: When possible, use reachable states and reachable probabilities instead. |
transition_function |
function
|
A callable function taking 3 arguments: s, a, s_p; and returning a float between 0.0 and 1.0. Can be None in the case a transition table is provided instead. Note: When possible, use reachable states and reachable probabilities instead. |
observation_table |
ndarray
|
A 3D matrix of shape S x A x O representing the probabilies of obsevating o when taking action a and leading to state s_p. |
reachable_states |
ndarray
|
A 3D array of the shape S x A x R, where R is max amount to states that can be reached from any state-action pair. |
reachable_probabilities |
ndarray
|
A 3D array of the same shape as reachable_states, the array represent the probability of reaching the state pointed by the reachable_states matrix. |
reachable_state_count |
int
|
The maximum of states that can be reached from any state-action combination. |
reachable_transitional_observation_table |
ndarray
|
A 4D array of shape S x A x O x R, representing the probabiliies of landing if each reachable state r, while observing o after having taken action a from state s. Mainly used to speedup repeated operations in solver. |
immediate_reward_table |
ndarray
|
A 3D matrix of shape S x A x S x O of the reward that will received when taking action a, in state s, landing in state s_p, and observing o. Can be None in the case an immediate rewards function is provided instead. |
immediate_reward_function |
function
|
A callable function taking 4 argments: s, a, s_p, o and returning the immediate reward the agent will receive. Can be None in the case an immediate rewards function is provided instead. |
expected_reward_table |
ndarray
|
A 2D array of shape S x A. It represents the rewards that is expected to be received when taking action a from state s. It is made by taking the weighted average of immediate rewards with the transitions and the observation probabilities. |
start_probabilities |
ndarray
|
A 1D array of length |S| containing the probility distribution of the agent starting in each state. |
rewards_are_probabilisitic |
bool
|
Whether the immediate rewards are probabilitic, ie: returning a 0 or 1 based on the reward that is considered to be a probability. |
end_states |
list[int]
|
A list of states that, when reached, terminate a simulation. |
end_actions |
list[int]
|
A list of actions that, when taken, terminate a simulation. |
is_on_gpu |
bool
|
Whether the numpy array of the model are stored on the gpu or not. |
gpu_model |
Model
|
An equivalent model with the np.ndarray objects on GPU. (If already on GPU, returns self) |
cpu_model |
Model
|
An equivalent model with the np.ndarray objects on CPU. (If already on CPU, returns self) |
seed |
int
|
The seed used for the random operations (to allow for reproducability). |
rnd_state |
RandomState
|
The random state variable used to generate random values. |
Source code in olfactory_navigation/agents/model_based_util/pomdp.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
_end_reward_function(s, a, sn, o)
The default reward function. Returns 1 if the next state sn is in the end states or if the action is in the end actions (terminating actions)
Source code in olfactory_navigation/agents/model_based_util/pomdp.py
246 247 248 249 250 251 |
|
observe(s_p, a)
Returns a random observation knowing action a is taken from state s, it is weighted by the observation probabilities.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s_p
|
int
|
The state landed on after having done action a. |
required |
a
|
int
|
The action to take. |
required |
Returns:
Name | Type | Description |
---|---|---|
o |
int
|
A random observation. |
Source code in olfactory_navigation/agents/model_based_util/pomdp.py
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
reward(s, a, s_p, o)
Returns the rewards of playing action a when in state s and landing in state s_p. If the rewards are probabilistic, it will return 0 or 1.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
s
|
int
|
The current state. |
required |
a
|
int
|
The action taking in state s. |
required |
s_p
|
int
|
The state landing in after taking action a in state s |
required |
o
|
int
|
The observation that is done after having played action a in state s and landing in s_p |
required |
Returns:
Name | Type | Description |
---|---|---|
reward |
int or float
|
The reward received. |
Source code in olfactory_navigation/agents/model_based_util/pomdp.py
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 |
|