WIP: DQN #5

Draft
cosmic wants to merge 23 commits from ml/alg/dqn into main
Owner

This branch begins the actual ML implementation of our project, using one of the most simple, yet foundational forms of Reinforcement Learning, Deep Q-Networks, particularly the DQN-Nature 2015 implementation. http://www.nature.com/doifinder/10.1038/nature14236 //
https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf

The trainer creates a PlayEnvironment where it runs many episodes with a single agent that explores the environment.

The agent is randomly initialized and initially explores randomly, storing its experiences in a replay buffer. An experience is a tuple containing {state, move, new_state, reward}. After this warmup phase, it follows an ϵ-greedy policy, where it typically attempts to exploit its knowledge and executes what it believes to be the best move, but, occasionally (ϵ% of the time), it takes a random move instead forcing it to explore to different strategies.

Experiences are sampled from the replay buffer and used to train a neural network whose output logits are the expected reward of taking each possible action tuple (card, position). A reward is the difference of the agent's score after taking an action compared to its score before taking an action.

Since the agent can take multiple actions each episode, the Q network's estimated reward should not only be the observed reward of that single action, but its anticipated reward of the game state it transitioned to. For terminal states (the game ends after taking the action), there is no additional anticipated reward. For all other actions, we use a target-network (Q̂) to estimate the total discounted future rewards.

Logging is sent to MLFLow using MLFlowObserver.

This branch begins the actual ML implementation of our project, using one of the most simple, yet foundational forms of Reinforcement Learning, Deep Q-Networks, particularly the DQN-Nature 2015 implementation. http://www.nature.com/doifinder/10.1038/nature14236 // https://storage.googleapis.com/deepmind-media/dqn/DQNNaturePaper.pdf The trainer creates a PlayEnvironment where it runs many episodes with a single agent that explores the environment. The agent is randomly initialized and initially explores randomly, storing its experiences in a replay buffer. An experience is a tuple containing {state, move, new_state, reward}. After this warmup phase, it follows an ϵ-greedy policy, where it typically attempts to exploit its knowledge and executes what it believes to be the best move, but, occasionally (ϵ% of the time), it takes a random move instead forcing it to explore to different strategies. Experiences are sampled from the replay buffer and used to train a neural network whose output logits are the expected reward of taking each possible action tuple `(card, position)`. A reward is the difference of the agent's score after taking an action compared to its score before taking an action. Since the agent can take multiple actions each episode, the Q network's estimated reward should not only be the observed reward of that single action, but its anticipated reward of the game state it transitioned to. For terminal states (the game ends after taking the action), there is no additional anticipated reward. For all other actions, we use a target-network (Q̂) to estimate the total discounted future rewards. Logging is sent to MLFLow using MLFlowObserver.
Author
Owner

Songbirds has several aspects that make it significantly challenging as a RL target.

  • Like most card games, it is only partially observable {in SoloPlay, what is in the deck is known, but what is unknown is the order of the cards} and the number of startup states is enormous even from the first move.

  • (card, pos) tuples are extremely sparse: each card can only be played once each game, and each position can only be played one each game. And, in addition, the output space is enormous, DQN-Atari has only 18 actions available each frame.

  • similarly, the input is rather sparse; 2 out of 28 cards in hand, and up to 25 cards in play, but beginning only with 9.

  • rewards are deterministic but delayed: reserving the wrong suit is catastrophic as the model observes 0 rewards for several actions and then suddenly a massive negative reward. This may cause an agent to learn a policy that always draws by never reserving a card. See attachment of an example: random play would result in not reserving ~1/17 of the time, but the agent fails to reserve 50% of the time. Optimal play may include not reserving a card in hopeless board states, but an experienced player presumably shouldn't be playing hopless board states.

Songbirds has several aspects that make it significantly challenging as a RL target. * Like most card games, it is only partially observable {in SoloPlay, what is in the deck is known, but what is unknown is the order of the cards} and the number of startup states is enormous even from the first move. * `(card, pos)` tuples are extremely sparse: each card can only be played once each game, and each position can only be played one each game. And, in addition, the output space is enormous, DQN-Atari has only 18 actions available each frame. * similarly, the input is rather sparse; 2 out of 28 cards in hand, and up to 25 cards in play, but beginning only with 9. * rewards are deterministic but delayed: reserving the wrong suit is catastrophic as the model observes 0 rewards for several actions and then suddenly a massive negative reward. This may cause an agent to learn a policy that always draws by never reserving a card. See attachment of an example: random play would result in not reserving ~1/17 of the time, but the agent fails to reserve 50% of the time. Optimal play may include not reserving a card in hopeless board states, but an experienced player presumably shouldn't be playing hopless board states.
This pull request is marked as a work in progress.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin ml/alg/dqn:ml/alg/dqn
git switch ml/alg/dqn

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch main
git merge --no-ff ml/alg/dqn
git switch ml/alg/dqn
git rebase main
git switch main
git merge --ff-only ml/alg/dqn
git switch ml/alg/dqn
git rebase main
git switch main
git merge --no-ff ml/alg/dqn
git switch main
git merge --squash ml/alg/dqn
git switch main
git merge --ff-only ml/alg/dqn
git switch main
git merge ml/alg/dqn
git push origin main
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
cosmic/songbirds!5
No description provided.