fix(rl): credit hit reward to the action that caused the collision#6
Open
GERD0GDU wants to merge 1 commit into
Open
fix(rl): credit hit reward to the action that caused the collision#6GERD0GDU wants to merge 1 commit into
GERD0GDU wants to merge 1 commit into
Conversation
GameSimulator.Update runs UpdateBall (which sets paddle.HasHitBall) before UpdatePaddles applies the current frame's action. When HasHitBall is true in frame N, the collision happened with the paddle position established by action N-1, not the action just buffered in this frame's Decide(). RegisterReward(+1) was attaching the only positive signal to buffer[Count-1] — the unrelated action just decided — turning the hit reward into pure noise and explaining the persistent policy collapse (paddle always drifts up or down without learning to track the ball). Add RegisterRewardForPreviousAction that writes to buffer[Count-2] and use it for the hit-step reward. Terminal reward in EndEpisode still uses the last action (correct: it credits the action that preceded the miss). Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_014E7V6Etbi1qzrTDpFbtsp2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Sorun
RL ajanı (AIReinforcementAgent) sürekli yukarı veya aşağı yöne yığılıyor, topu takip etmeyi öğrenmiyor. Önceki PR'da (#5 / Faz 3.5) Xavier init + baseline + hiperparametre ayarları denendi ama collapse çözülmedi.
Asıl kök neden bir off-by-one credit assignment hatası:
GameSimulator.Update()içinde sıralama şudur:UpdateBall(dt)— top hareket eder, paddle ile çarpışma kontrol edilir → çarpışma varsapaddle.HasHitBall = trueUpdatePaddles(dt)— paddle bu frame'in action'ı ile hareket ederYani frame N'de
HasHitBall=truegörüldüğünde, çarpışma paddle'ın action N-1 sonrası pozisyonu ile gerçekleşti — bu frame'de Decide()'da seçilen action N henüz paddle'a uygulanmadan önce.Ama
MainWindow.UpdateRL:RegisterReward,_episodeBuffer[Count-1]'e yazıyordu — bu da bu frame'de Decide()'da az önce buffer'a eklenen action N. Yani topla alakası olmayan bir action'a kredi veriliyordu.Vanilla REINFORCE'da tek pozitif sinyal hit reward'ı olduğu için, bu sinyal sürekli rastgele action'lara dağıtılınca politika kararlı bir yön (sürekli yukarı/aşağı) öğrenmeye yöneliyor — kollaps.
Çözüm
AIReinforcementAgent'a yeni metod ekledim:MainWindow.UpdateRL'de hit reward bu metodu kullanıyor. Terminal reward (EndEpisodeiçinden çağrılanRegisterReward) hâlâ son action'a yazıyor — bu doğru, çünkü kaçırılan top için suçlu son action'tır.Değişen dosyalar
src/PingPongAI.AI/Agents/AIReinforcementAgent.cs— yeniRegisterRewardForPreviousActionmetodusrc/PingPongAI.App/MainWindow.xaml.cs—UpdateRLiçinde tek satır değişiklikTest planı
weights/left.jsonveweights/right.jsonvarsa SİL (eski politika yanlış kredilemeyle eğitilmiş, baştan başlamak gerek)Generated by Claude Code