डीनिंग बेलमैन के समीकरण रीइनफोर्समेंट लर्निंग में


32

मैं " इन रिइनफोर्समेंट लर्निंग। एन इंट्रोडक्शन " में निम्नलिखित समीकरण देखता हूं , लेकिन मैंने नीचे नीले रंग में हाइलाइट किए गए चरण का पालन नहीं किया है। यह कदम वास्तव में कैसे प्राप्त होता है?

यहां छवि विवरण दर्ज करें

जवाबों:


7

यह उन सभी के लिए उत्तर है जो इसके पीछे स्वच्छ, संरचित गणित के बारे में आश्चर्य करते हैं (यानी यदि आप ऐसे लोगों के समूह से संबंधित हैं जो जानते हैं कि एक यादृच्छिक चर क्या है और आपको यह दिखाना या मान लेना चाहिए कि यादृच्छिक चर का घनत्व है तो यह है) आपके लिए जवाब ;-)):

सबसे पहले हमें यह बताना होगा कि मार्कोव निर्णय प्रक्रिया में केवल L1 ड्रायर्स की एक परिमित संख्या है , अर्थात हमें यह आवश्यक है कि घनत्व का एक E निर्धारित सेट मौजूद है , प्रत्येक L1 चर से संबंधित है , अर्थातRxe(x)dx< सभी के लिएeE और एक नक्शाF:A×SE ऐसी है कि

p(rt|at,st)=F(at,st)(rt)
(यानी एमडीपी के पीछे ऑटोमेटा में, कई राज्यों में असीम रूप से हो सकता है, लेकिन राज्यों केबीच संभवतः अनंत संक्रमणों सेकेवल बहुत कमL1 -वितरण-संलग्न हैं)

प्रमेय 1 : Let XL1(Ω) (यानी एक समाकलनीय असली यादृच्छिक चर) और जाने Y एक और यादृच्छिक चर ऐसी है कि हो सकता है X,Y एक आम घनत्व है तो

E[X|Y=y]=Rxp(x|y)dx

प्रमाण : आवश्यक रूप से यहां स्टीफन हेंसन द्वारा सिद्ध किया गया है।

प्रमेय 2 : Let XL1(Ω) और जाने Y,Z आगे यादृच्छिक परिवर्तनीय हो ऐसी है कि X,Y,Z एक आम घनत्व है तो

E[X|Y=y]=Zp(z|y)E[X|Y=y,Z=z]dz
जहां ZZ की सीमा है ।

प्रमाण :

E[X|Y=y]=Rxp(x|y)dx    (by Thm. 1)=Rxp(x,y)p(y)dx=RxZp(x,y,z)dzp(y)dx=ZRxp(x,y,z)p(y)dxdz=ZRxp(x|y,z)p(z|y)dxdz=Zp(z|y)Rxp(x|y,z)dxdz=Zp(z|y)E[X|Y=y,Z=z]dz    (by Thm. 1)

Put Gt=k=0γkRt+k and put Gt(K)=k=0KγkRt+k then one can show (using the fact that the MDP has only finitely many L1-rewards) that Gt(K) converges and that since the function k=0γk|Rt+k| is still in L1(Ω) (i.e. integrable) one can also show (by using the usual combination of the theorems of monotone convergence and then dominated convergence on the defining equations for [the factorizations of] the conditional expectation) that

limKE[Gt(K)|St=st]=E[Gt|St=st]
Now one shows that
E[Gt(K)|St=st]=E[Rt|St=st]+γSp(st+1|st)E[Gt+1(K1)|St+1=st+1]dst+1
using Gt(K)=Rt+γGt+1(K1), Thm. 2 above then Thm. 1 on E[Gt+1(K1)|St+1=s,St=st] and then using a straightforward marginalization war, one shows that p(rq|st+1,st)=p(rq|st+1) for all qt+1. Now we need to apply the limit K to both sides of the equation. In order to pull the limit into the integral over the state space S we need to make some additional assumptions:

Either the state space is finite (then S=S and the sum is finite) or all the rewards are all positive (then we use monotone convergence) or all the rewards are negative (then we put a minus sign in front of the equation and use monotone convergence again) or all the rewards are bounded (then we use dominated convergence). Then (by applying limK to both sides of the partial / finite Bellman equation above) we obtain

E[Gt|St=st]=E[Gt(K)|St=st]=E[Rt|St=st]+γSp(st+1|st)E[Gt+1|St+1=st+1]dst+1

and then the rest is usual density manipulation.

REMARK: Even in very simple tasks the state space can be infinite! One example would be the 'balancing a pole'-task. The state is essentially the angle of the pole (a value in [0,2π), an uncountably infinite set!)

REMARK: People might comment 'dough, this proof can be shortened much more if you just use the density of Gt directly and show that p(gt+1|st+1,st)=p(gt+1|st+1)' ... BUT ... my questions would be:

  1. How come that you even know that Gt+1 has a density?
  2. How come that you even know that Gt+1 has a common density together with St+1,St?
  3. How do you infer that p(gt+1|st+1,st)=p(gt+1|st+1)? This is not only the Markov property: The Markov property only tells you something about the marginal distributions but these do not necessarily determine the whole distribution, see e.g. multivariate Gaussians!

10

Let total sum of discounted rewards after time t be:
Gt=Rt+1+γRt+2+γ2Rt+3+...

Utility value of starting in state,s at time,t is equivalent to expected sum of
discounted rewards R of executing policy π starting from state s onwards.
Uπ(St=s)=Eπ[Gt|St=s]
=Eπ[(Rt+1+γRt+2+γ2Rt+3+...)|St=s] By definition of Gt
=Eπ[(Rt+1+γ(Rt+2+γRt+3+...))|St=s]
=Eπ[(Rt+1+γ(Gt+1))|St=s]
=Eπ[Rt+1|St=s]+γEπ[Gt+1|St=s] By law of linearity
=Eπ[Rt+1|St=s]+γEπ[Eπ(Gt+1|St+1=s)|St=s] By law of Total Expectation
=Eπ[Rt+1|St=s]+γEπ[Uπ(St+1=s)|St=s] By definition of Uπ
=Eπ[Rt+1+γUπ(St+1=s)|St=s] By law of linearity

Assuming that the process satisfies Markov Property:
Probability Pr of ending up in state s having started from state s and taken action a ,
Pr(s|s,a)=Pr(St+1=s,St=s,At=a) and
Reward R of ending up in state s having started from state s and taken action a,
R(s,a,s)=[Rt+1|St=s,At=a,St+1=s]

Therefore we can re-write above utility equation as,
=aπ(a|s)sPr(s|s,a)[R(s,a,s)+γUπ(St+1=s)]

Where; π(a|s) : Probability of taking action a when in state s for a stochastic policy. For deterministic policy, aπ(a|s)=1


Just a few notes: The sum over π equals to 1 even in a stochastic policy, but in a deterministic policy, there is just one action that receives the full weight (ie, π(a|s)=1 and the rest receive 0 weight, so that term is removed from the equation. Also in the line you used the law of total expectation, the order of the condtionals is reversed
Gilad Peleg

1
I am pretty sure that this answer is incorrect: Let us follow the equations just until the line involving the law of total expectation. Then the left hand side does not depend on s while the right hand side does... I.e. if the equations are correct then for which s are they correct? You must have some kind of integral over s already at that stage. The reason is probably your misunderstanding of the difference of E[X|Y] (a random variable) vs. its factorization E[X|Y=y] (a deterministic function!)...
Fabian Werner

@FabianWerner I agree this is not correct. The answer from Jie Shi is the right answer.
teucer

@teucer This answer can be fixed because there is just missing some "symmetrization", i.e. E[A|C=c]=range(B)p(b|c)E[A|B=b,C=c]dPB(b) but still, the question is the same as in Jie Shis answer: Why is E[Gt+1|St+1=st+1,St=st]=E[Gt+1|St+1=st+1]? This is not only the Markov property because Gt+1 is a really complicated RV: Does it even converge? If so, where? What is the common density p(gt+1,st+1,st)? We only know this expression for finite sums (complicated convolution) but for the infinite case?
Fabian Werner

@FabianWerner not sure if I can answer all the questions. Below some pointers. For the convergence of the Gt+1, given that it is the sum of discounted rewards, it is reasonable to assume that the series converges (discounting factor is <1 and to where it converges does not really matter). I don't get the concern with the density (one can always define a joint density as long as we have random variables), it only matters if it is well defined and in that case it is.
teucer

8

Here is my proof. It is based on the manipulation of conditional distributions, which makes it easier to follow. Hope this one helps you.

vπ(s)=E[Gt|St=s]=E[Rt+1+γGt+1|St=s]=srgt+1ap(s,r,gt+1,a|s)(r+γgt+1)=ap(a|s)srgt+1p(s,r,gt+1|a,s)(r+γgt+1)=ap(a|s)srgt+1p(s,r|a,s)p(gt+1|s,r,a,s)(r+γgt+1)Note that p(gt+1|s,r,a,s)=p(gt+1|s) by assumption of MDP=ap(a|s)srp(s,r|a,s)gt+1p(gt+1|s)(r+γgt+1)=ap(a|s)srp(s,r|a,s)(r+γgt+1p(gt+1|s)gt+1)=ap(a|s)srp(s,r|a,s)(r+γvπ(s))
This is the famous Bellman equation.


Gt+1

Gt+1Gt+1=Rt+2+Rt+3+. Note that Rt+2 only directly depends on St+1 and At+1 since p(s,r|s,a) captures all the transition information of a MDP (More precisely, Rt+2 is independent of all states, actions, and rewards before time t+1 given St+1 and At+1). Similarly, Rt+3 only depends on St+2 and At+2. As a result, Gt+1 is independent of St, At, and Rt given St+1, which explains that line.
Jie Shi

Sorry, that only 'motivates' it, it doesn't actually explain anything. For example: What is the density of Gt+1? Why are you sure that p(gt+1|st+1,st)=p(gt+1|st+1)? Why do these random variables even have a common density? You know that a sum transforms into a convolution in densities so what... Gt+1 should have an infinite amount of integrals in the density??? There is absolutely no candidate for the density!
Fabian Werner

To Fabian: I do not get your question. 1. You want the exact form of the marginal distribution p(gt+1)? I do not know it and we do not need it in this proof. 2. why p(gt+1|st+1,st)=p(gt+1|st+1)? Because as I mentioned earlier gt+1 and st are independent given st+1. 3. What do you mean by "common density"? You mean joint distribution? You want to know why these random variables have a joint distribution? All random variables in this universe can have a joint distribution. If this is your question, I would suggest you find a probability theory book and read it.
Jie Shi


2

What's with the following approach?

vπ(s)=Eπ[GtSt=s]=Eπ[Rt+1+γGt+1St=s]=aπ(as)srp(s,rs,a)Eπ[Rt+1+γGt+1St=s,At+1=a,St+1=s,Rt+1=r]=aπ(as)s,rp(s,rs,a)[r+γvπ(s)].

The sums are introduced in order to retrieve a, s and r from s. After all, the possible actions and possible next states can be . With these extra conditions, the linearity of the expectation leads to the result almost directly.

I am not sure how rigorous my argument is mathematically, though. I am open for improvements.


The last line only works because of the MDP property.
teucer

2

This is just a comment/addition to the accepted answer.

I was confused at the line where law of total expectation is being applied. I don't think the main form of law of total expectation can help here. A variant of that is in fact needed here.

If X,Y,Z are random variables and assuming all the expectation exists, then the following identity holds:

E[X|Y]=E[E[X|Y,Z]|Y]

In this case, X=Gt+1, Y=St and Z=St+1. Then

E[Gt+1|St=s]=E[E[Gt+1|St=s,St+1=s|St=s], which by Markov property eqauls to E[E[Gt+1|St+1=s]|St=s]

From there, one could follow the rest of the proof from the answer.


1
Welcome to CV! Please use the answers only for answering the question. Once you have enough reputation (50), you can add comments.
Frans Rodenburg

Thank you. Yes, since I could not comment due to not having enough reputation, I thought it might be useful to add the explanation to the answers. But I will keep that in mind.
Mehdi Golari

I upvoted but still, this answer is missing details: Even if E[X|Y] satisfies this crazy relationship then nobody guarantees that this is true for the factorizations of the conditional expectations as well! I.e. as in the case with the answer of Ntabgoba: The left hand side does not depend on s while the right hand side does. This equation cannot be correct!
Fabian Werner

1

Eπ() usually denotes the expectation assuming the agent follows policy π. In this case π(a|s) seems non-deterministic, i.e. returns the probability that the agent takes action a when in state s.

It looks like r, lower-case, is replacing Rt+1, a random variable. The second expectation replaces the infinite sum, to reflect the assumption that we continue to follow π for all future t. s,rrp(s,r|s,a) is then the expected immediate reward on the next time step; The second expectation—which becomes vπ—is the expected value of the next state, weighted by the probability of winding up in state s having taken a from s.

Thus, the expectation accounts for the policy probability as well as the transition and reward functions, here expressed together as p(s,r|s,a).


Thanks. Yes, what you mentioned about π(a|s) is correct (it's the probability of the agent taking action a when in state s).
Amelio Vazquez-Reina

What I don't follow is what terms exactly get expanded into what terms in the second step (I'm familiar with probability factorization and marginalization, but not so much with RL). Is Rt the term being expanded? I.e. what exactly in the previous step equals what exactly in the next step?
Amelio Vazquez-Reina

1
It looks like r, lower-case, is replacing Rt+1, a random variable, and the second expectation replaces the infinite sum (probably to reflect the assumption that we continue to follow π for all future t). Σp(s,r|s,a)r is then the expected immediate reward on the next time step, and the second expectation—which becomes vπ—is the expected value of the next state, weighted by the probability of winding up in state s having taken a from s.
Sean Easter

1

even though the correct answer has already been given and some time has passed, I thought the following step by step guide might be useful:
By linearity of the Expected Value we can split E[Rt+1+γE[Gt+1|St=s]] into E[Rt+1|St=s] and γE[Gt+1|St=s].
I will outline the steps only for the first part, as the second part follows by the same steps combined with the Law of Total Expectation.

E[Rt+1|St=s]=rrP[Rt+1=r|St=s]=arrP[Rt+1=r,At=a|St=s](III)=arrP[Rt+1=r|At=a,St=s]P[At=a|St=s]=sarrP[St+1=s,Rt+1=r|At=a,St=s]P[At=a|St=s]=aπ(a|s)s,rp(s,r|s,a)r

Whereas (III) follows form:

P[A,B|C]=P[A,B,C]P[C]=P[A,B,C]P[C]P[B,C]P[B,C]=P[A,B,C]P[B,C]P[B,C]P[C]=P[A|B,C]P[B|C]


1

I know there is already an accepted answer, but I wish to provide a probably more concrete derivation. I would also like to mention that although @Jie Shi trick somewhat makes sense, but it makes me feel very uncomfortable:(. We need to consider the time dimension to make this work. And it is important to note that, the expectation is actually taken over the entire infinite horizon, rather than just over s and s. Let assume we start from t=0 (in fact, the derivation is the same regardless of the starting time; I do not want to contaminate the equations with another subscript k)

vπ(s0)=Eπ[G0|s0]G0=t=0T1γtRt+1Eπ[G0|s0]=a0π(a0|s0)a1,...aTs1,...sTr1,...rT(t=0T1π(at+1|st+1)p(st+1,rt+1|st,at)×(t=0T1γtrt+1))=a0π(a0|s0)a1,...aTs1,...sTr1,...rT(t=0T1π(at+1|st+1)p(st+1,rt+1|st,at)×(r1+γt=0T2γtrt+2))
NOTED THAT THE ABOVE EQUATION HOLDS EVEN IF T, IN FACT IT WILL BE TRUE UNTIL THE END OF UNIVERSE (maybe be a bit exaggerated :) )
At this stage, I believe most of us should already have in mind how the above leads to the final expression--we just need to apply sum-product rule(abcabcaabbcc) painstakingly. Let us apply the law of linearity of Expectation to each term inside the (r1+γt=0T2γtrt+2)

Part 1

a0π(a0|s0)a1,...aTs1,...sTr1,...rT(t=0T1π(at+1|st+1)p(st+1,rt+1|st,at)×r1)

Well this is rather trivial, all probabilities disappear (actually sum to 1) except those related to r1. Therefore, we have

a0π(a0|s0)s1,r1p(s1,r1|s0,a0)×r1

Part 2
Guess what, this part is even more trivial--it only involves rearranging the sequence of summations.

a0π(a0|s0)a1,...aTs1,...sTr1,...rT(t=0T1π(at+1|st+1)p(st+1,rt+1|st,at))=a0π(a0|s0)s1,r1p(s1,r1|s0,a0)(a1π(a1|s1)a2,...aTs2,...sTr2,...rT(t=0T2π(at+2|st+2)p(st+2,rt+2|st+1,at+1)))

And Eureka!! we recover a recursive pattern in side the big parentheses. Let us combine it with γt=0T2γtrt+2, and we obtain vπ(s1)=Eπ[G1|s1]

γEπ[G1|s1]=a1π(a1|s1)a2,...aTs2,...sTr2,...rT(t=0T2π(at+2|st+2)p(st+2,rt+2|st+1,at+1))(γt=0T2γtrt+2)

and part 2 becomes
a0π(a0|s0)s1,r1p(s1,r1|s0,a0)×γvπ(s1)

Part 1 + Part 2

vπ(s0)=a0π(a0|s0)s1,r1p(s1,r1|s0,a0)×(r1+γvπ(s1))

And now if we can tuck in the time dimension and recover the general recursive formulae

vπ(s)=aπ(a|s)s,rp(s,r|s,a)×(r+γvπ(s))

Final confession, I laughed when I saw people above mention the use of law of total expectation. So here I am


Erm... what is the symbol 'a0,...,a' supposed to mean? There is no a...
Fabian Werner

Another question: Why is the very first equation true? I know E[f(X)|Y=y]=Xf(x)p(x|y)dx but in our case, X would be an infinite sequence of random variables (R0,R1,R2,........) so we would need to compute the density of this variable (consisting of an infinite amount of variables of which we know the density) together with something else (namely the state)... how exactly do you du that? I.e. what is p(r0,r1,....)?
Fabian Werner

@FabianWerner. Take a deep breath to calm your brain first:). Let me answer your first question. a0,...,aa0a1,...,a. If you recall the definition of the value function, it is actually a summation of discounted future rewards. If we consider an infinite horizon for our future rewards, we then need to sum infinite number of times. A reward is result of taking an action from a state, since there is an infinite number of rewards, there should be an infinite number of actions, hence a.
Karlsson Yu

1
let us assume that I agree that there is some weird a (which I still doubt, usually, students in the very first semester in math tend to confuse the limit with some construction that actually involves an infinite element)... I still have one simple question: how is “a1...a defined? I know what this expression is supposed to mean with a finite amount of sums... but infinitely many of them? What do you understand that this expression does?
Fabian Werner

1
internet. Could you refer me to a page or any place that defines your expression? If not then you actually defined something new and there is no point in discussing that because it is just a symbol that you made up (but there is no meaning behind it)... you agree that we are only able to discuss about the symbol if we both know what it means, right? So, I do not know what it means, please explain...
Fabian Werner

1

There are already a great many answers to this question, but most involve few words describing what is going on in the manipulations. I'm going to answer it using way more words, I think. To start,

Gtk=t+1Tγkt1Rk

is defined in equation 3.11 of Sutton and Barto, with a constant discount factor 0γ1 and we can have T= or γ=1, but not both. Since the rewards, Rk, are random variables, so is Gt as it is merely a linear combination of random variables.

vπ(s)Eπ[GtSt=s]=Eπ[Rt+1+γGt+1St=s]=Eπ[Rt+1|St=s]+γEπ[Gt+1|St=s]

That last line follows from the linearity of expectation values. Rt+1 is the reward the agent gains after taking action at time step t. For simplicity, I assume that it can take on a finite number of values rR.

Work on the first term. In words, I need to compute the expectation values of Rt+1 given that we know that the current state is s. The formula for this is

Eπ[Rt+1|St=s]=rRrp(r|s).

In other words the probability of the appearance of reward r is conditioned on the state s; different states may have different rewards. This p(r|s) distribution is a marginal distribution of a distribution that also contained the variables a and s, the action taken at time t and the state at time t+1 after the action, respectively:

p(r|s)=sSaAp(s,a,r|s)=sSaAπ(a|s)p(s,r|a,s).

Where I have used π(a|s)p(a|s), following the book's convention. If that last equality is confusing, forget the sums, suppress the s (the probability now looks like a joint probability), use the law of multiplication and finally reintroduce the condition on s in all the new terms. It in now easy to see that the first term is

Eπ[Rt+1|St=s]=rRsSaArπ(a|s)p(s,r|a,s),

as required. On to the second term, where I assume that Gt+1 is a random variable that takes on a finite number of values gΓ. Just like the first term:

Eπ[Gt+1|St=s]=gΓgp(g|s).()

Once again, I "un-marginalize" the probability distribution by writing (law of multiplication again)

p(g|s)=rRsSaAp(s,r,a,g|s)=rRsSaAp(g|s,r,a,s)p(s,r,a|s)=rRsSaAp(g|s,r,a,s)p(s,r|a,s)π(a|s)=rRsSaAp(g|s,r,a,s)p(s,r|a,s)π(a|s)=rRsSaAp(g|s)p(s,r|a,s)π(a|s)()

The last line in there follows from the Markovian property. Remember that Gt+1 is the sum of all the future (discounted) rewards that the agent receives after state s. The Markovian property is that the process is memory-less with regards to previous states, actions and rewards. Future actions (and the rewards they reap) depend only on the state in which the action is taken, so p(g|s,r,a,s)=p(g|s), by assumption. Ok, so the second term in the proof is now

γEπ[Gt+1|St=s]=γgΓrRsSaAgp(g|s)p(s,r|a,s)π(a|s)=γrRsSaAEπ[Gt+1|St+1=s]p(s,r|a,s)π(a|s)=γrRsSaAvπ(s)p(s,r|a,s)π(a|s)

as required, once again. Combining the two terms completes the proof

vπ(s)Eπ[GtSt=s]=aAπ(a|s)rRsSp(s,r|a,s)[r+γvπ(s)].

UPDATE

I want to address what might look like a sleight of hand in the derivation of the second term. In the equation marked with (), I use a term p(g|s) and then later in the equation marked () I claim that g doesn't depend on s, by arguing the Markovian property. So, you might say that if this is the case, then p(g|s)=p(g). But this is not true. I can take p(g|s,r,a,s)p(g|s) because the probability on the left side of that statement says that this is the probability of g conditioned on s, a, r, and s. Because we either know or assume the state s, none of the other conditionals matter, because of the Markovian property. If you do not know or assume the state s, then the future rewards (the meaning of g) will depend on which state you begin at, because that will determine (based on the policy) which state s you start at when computing g.

If that argument doesn't convince you, try to compute what p(g) is:

p(g)=sSp(g,s)=sSp(g|s)p(s)=sSp(g|s)s,a,rp(s,a,r,s)=sSp(g|s)s,a,rp(s,r|a,s)p(a,s)=sSp(s)sSp(g|s)a,rp(s,r|a,s)π(a|s)sSp(s)p(g|s)=sSp(g,s)=p(g).

As can be seen in the last line, it is not true that p(g|s)=p(g). The expected value of g depends on which state you start in (i.e. the identity of s), if you do not know or assume the state s.

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.