# What is the relationship between the reward function and the value function?

To clarify it in my head, the value function calculates how 'good' it is to be in a certain state by summing all future (discounted) rewards, while the reward function is what the value function uses to 'generate' those rewards for it to use in the calculation of how 'good' it is to be in the state?

I think it is pedagogically useful to distinguish between the theory (equations) and the practice (algorithms).

If you're talking about the definition of the value function (the theory)

\begin{align} v_{\pi}(s) & \dot{=} \mathbb{E}_{\pi} \left[ G_t \mid S_t = s \right]\\ &= \mathbb{E}_{\pi} \left[ \sum_{k=0}^\infty \gamma^k R_{t+k+1} \bigl\vert S_t = s \right]\\ \end{align}

for all $$s \in \mathcal{S}$$, where $$\dot{=}$$ means "is defined as" and $$\mathcal{S}$$ is the state space, then the value function can be defined in terms of the reward, as it can be clearly seen above. (Note that $$R_{t+k+1}$$, $$G$$ and $$S_t$$ are random variables, and, in fact, expectations are taken with respect to random variables).

The definition above can actually be expanded to be a Bellman equation (i.e. a recursive equation) defined in terms of the reward function $$R(s, a)$$ of the underlying MDP. However, often, rather than the notation $$R(s, a)$$, you will see $$p(s', r \mid s, a)$$ (which represents the combination of the transition probability function and the reward function). Consequently, the value is a function of the reward.

If you're estimating a value function (the practice), e.g. using Q-learning, you don't necessarily use the reward function of the Markov decision process. You can estimate the value function by just observing the rewards that you receive while exploring the environment, without really knowing the reward function. But, by exploring the environment, you can actually estimate the reward function. For example, if every time you're in state $$s$$ you take action $$a$$ and you receive reward $$r$$, then you already know something about the actual underlying reward function. If you explore enough the MDP, you could potentially learn the reward function too (unless it keeps on changing, in that case, it may be more difficult to learn it).

To conclude, yes, value functions are certainly very related to reward functions and rewards, in ways that you immediately see from the equations that define the value functions.