Describing What an Action Changes
Watering changes the greenhouse Botie will face tomorrow. A state, an action, and a transition model let us describe that consequence before choosing a policy.
12 sections · 4 questions · 2 coding challenges
The arrow keys move between sections too.
Planning With a State That Changes After Each Choice
BOTIE
A Markov decision process supplies states, actions, transitions, and rewards. Our dry-or-moist greenhouse is a deliberately simplified model. Its value is that every transition can be inspected, not that two labels fully describe soil behaviour.
The Greenhouse Remembers What Botie Did Yesterday
A schedule's value depends on the soil. Watering a dry tray may help, while watering an already wet tray may waste water. The same action cannot be evaluated sensibly without describing the situation in which it is taken.
Let's describe the situations the greenhouse can be in. For each state, we need to know which actions Botie can take and what might happen after each action. The next state may be uncertain, so we will record transition probabilities. Along with the reward rule, these give us a small Markov decision process to investigate.
The transition probabilities define a small invented environment.
Step 1 of 3
Describe the situation
Use two state IDs with explicit meanings.
- State 0
- dry
- State 1
- moist
Step 2 of 3
Condition the next-state probabilities on an action
From dry soil, watering is assumed to reach moist soil more often than waiting.
| Chosen action | Next: dry | Next: moist |
|---|---|---|
| Water: next dry, moist | 0.1 | 0.9 |
| Wait: next dry, moist | 0.8 | 0.2 |
Water: next dry, moist
- Next: dry
- 0.1
- Next: moist
- 0.9
Wait: next dry, moist
- Next: dry
- 0.8
- Next: moist
- 0.2
Step 3 of 3
Keep value separate from probability
If the supplied next-state values are zero and ten, weight those values by the transition probabilities.
Dry: probability 0.1, value 0 Moist: probability 0.9, value 10 Expected later value = (0.1 × 0) + (0.9 × 10) = 9
An action is described by its possible consequences
Each row averages the same state values under a different action's possible consequences.
Where might each action leave the greenhouse?
An action can have several possible consequences. Change its transition probabilities while keeping each row a valid distribution, then compare the expected values of the next states.
BOTIE
Expected next-state value for each action
- 09
- 12
Follow the operations
1. Next-state probabilities per action
0.1 0.9 0.8 0.2 2. Check transition rows
0.1 0.9 0.8 0.2 3. Values in next-state order
- 00
- 110
4. Matrix times vector
- 09
- 12
5. Result
- 09
- 12
Transitions and values are supplied. Immediate rewards and a discount are introduced separately before selecting an action.
1. Choose a State That Contains the Needed Information
A state is the information used to predict the consequences of an action. The Markov assumption says that, given the current state and action, earlier history adds no further information about the next transition and reward distribution.
This is a modelling assumption, not a property guaranteed by giving a variable the name state. If two trays have the same moisture label but different root conditions that affect outcomes, our state may omit important information.
Partial observations may require remembering history or maintaining a belief over hidden states.
2. Describe Actions, Rewards, and Transition Rows
An action is a choice available in a state. A transition row gives probabilities for the possible next states after that choice. Entries must be non-negative and sum to one. A reward describes immediate feedback, which may depend on the transition as well.
Keep the next-state order fixed across transition rows and value vectors. Multiplying a probability by the wrong state's value can produce a plausible but meaningless result.
Next states: [dry, moist]
P(next | dry, water) = [0.1,0.9]
P(next | dry, wait) = [0.8,0.2]The transition probabilities are supplied assumptions in this lesson, not estimated greenhouse measurements.
3. A Policy Connects States to Choices
A deterministic policy selects one action in each state. A stochastic policy assigns action probabilities. Either can behave differently in dry and moist states.
A transition model describes what the environment does after an action; a policy describes which action the agent chooses. Do not confuse the two probability tables.
Example policy:
if dry: water
if moist: waitThe policy can be evaluated under the transition model even before learning a policy from experience.
Account for one action's possible next states
Suppose waiting leaves the bed dry with probability three quarters and moist otherwise. The two state values describe what those consequences are worth.
import numpy as np
transition = np.array([0.75, 0.25])
state_values = np.array([0., 8.])
contributions = transition * state_values
print(contributions.tolist())
print(float(contributions.sum()))[0.0, 2.0]
2.0The expected value weights both possible outcomes. It is not a claim that the next state will have value two; this environment only has the two supplied states.
4. Calculate an Expected Next-State Value
Multiply each possible next state's supplied value by its transition probability, then add. This is an expectation over possible outcomes, not a prediction that one trial will return the average outcome.
A complete action comparison adds immediate expected reward and an appropriate future discount. We will introduce that accumulation next; Botie's construction here isolates the expectation step.
Expected next value after watering
= 0.1 × 0 + 0.9 × 10
= 9A single transition still lands in one state. Repeated trials need not equal the expectation exactly.
5. The Same Observation Can Hide Different Situations
A dry-soil reading can occur immediately after a sensor fault or after several days without water. If those situations have different next outcomes under the same action, the reading alone may not supply a useful Markov state.
Add relevant history or maintain a belief over hidden conditions when needed. The Markov assumption says the chosen state contains the information needed for predicting the next transition. Naming an array state does not make that assumption true.
6. Check That Each Action Defines a Distribution
For each current state and action, the next-state probabilities should be nonnegative and sum to one. Their positions must refer to the same state vocabulary throughout the model.
An expected-value calculation averages across those outcomes. A simulated transition instead draws one outcome from that distribution. Confusing the two can produce a learner that experiences averaged states that do not actually exist.
Calculate the distribution and its expected continuation
The two entries are dry and moist. This row describes the result of watering a dry tray.
import numpy as np
probability = np.array([.2,.8])
next_value = np.array([-2.,3.])
print(bool((probability >= 0).all() and np.isclose(probability.sum(), 1)))
print(round(float(probability@next_value), 3))True
2.0The expected value is two, but the next state is still either dry or moist. It is not a new state halfway between them.
Check yourself
Questions on Parts 1 to 6
Question 1 of 4
What is the expected next-state value?
Use the information below.
Next-state order: [dry,moist]. Probabilities after watering: [0.1,0.9]. Values: [0,10].Try it with Botie
Build with Botie
Write and run Python