### Install PyQt5 Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/scripts/poker_gui_guide.md Install the PyQt5 library, which is a dependency for the GUI. Run this command in your terminal. ```bash pip install PyQt5 ``` -------------------------------- ### Install Project Dependencies Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Clone the repository, set up a virtual environment, and install required packages using pip. ```bash git clone https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players.git cd deepcfr-texas-no-limit-holdem-6-players python3 -m venv .venv source .venv/bin/activate pip install -r requirements.txt ``` -------------------------------- ### Basic Opponent-Modeling Training Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Starts basic opponent-modeling training. Configure iterations, traversals, and save/log directories. ```python python -m src.training.train_with_opponent_modeling \ --iterations 1000 \ --traversals 200 \ --save-dir models_om \ --log-dir logs/deepcfr_om ``` -------------------------------- ### Start TensorBoard Server for Monitoring Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Launches the TensorBoard server to visualize training metrics. Use --logdir to specify the directory containing log files. Access the dashboard via http://localhost:6006. ```bash # Start TensorBoard server tensorboard --logdir=logs ``` ```bash # Or specify multiple log directories tensorboard --logdir=phase1:logs/phase1,selfplay:logs/selfplay,mixed:logs/mixed ``` -------------------------------- ### Initial Training with 200 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Starts the initial training process with 200 traversals per iteration. Offers a balance between exploration and exploitation. ```bash python train.py --iterations 1000 --traversals 200 --log-dir logs/200 --save-dir models/200 ``` -------------------------------- ### Initial Training with 100 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Starts the initial training process with 100 traversals per iteration. Use for basic strategy learning. ```bash python train.py --iterations 1000 --traversals 100 --log-dir logs/100 --save-dir models/100 ``` -------------------------------- ### Create and Run Random Agents Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initializes random agents and simulates a complete game, printing actions and final rewards. Ensure 'pokers' library is installed. ```python from src.agents.random_agent import RandomAgent import pokers as pkrs # Create random agents for all positions agents = [RandomAgent(player_id=i) for i in range(6)] # Create game state state = pkrs.State.from_seed(n_players=6, button=0, sb=1, bb=2, stake=200.0, seed=42) # Play a complete game while not state.final_state: current_player = state.current_player action = agents[current_player].choose_action(state) print(f"Player {current_player}: {action.action.name}", end="") if action.action == pkrs.ActionEnum.Raise: print(f" {action.amount:.2f}") else: print() state = state.apply_action(action) # Show results print("\nFinal rewards:") for i, player in enumerate(state.players_state): print(f" Player {i}: {player.reward:+.2f}") ``` -------------------------------- ### Initial Training with 400 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Starts the initial training process with 400 traversals per iteration. This higher count is for more refined strategy learning. ```bash python train.py --iterations 1000 --traversals 400 --log-dir logs/400 --save-dir models/400 ``` -------------------------------- ### Self-Play Training (Python) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Programmatically starts self-play training from a checkpoint, specifying additional iterations and opponent training parameters. ```python from src.training.train import train_against_checkpoint agent, losses, profits = train_against_checkpoint( checkpoint_path="models/phase1/checkpoint_iter_1000.pt", additional_iterations=2000, traversals_per_iteration=400, save_dir="models/selfplay", log_dir="logs/selfplay", verbose=False ) # Evaluation results include both checkpoint and random opponents print(f"Final profit vs checkpoint: tracked in tensorboard") print(f"Final profit vs random: {profits[-1]:.2f}") ``` -------------------------------- ### PokerNetwork Forward Pass Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Instantiate the PokerNetwork, encode a game state, and perform a forward pass to get action logits and bet size predictions. Apply softmax to action logits to obtain action probabilities. ```python import torch from src.core.model import PokerNetwork, encode_state import pokers as pkrs # Create network (input_size based on state encoding) input_size = 52 + 52 + 5 + 1 + 6 + 6 + 6*4 + 1 + 4 + 5 # = 145 for 6 players network = PokerNetwork(input_size=input_size, hidden_size=256, num_actions=3) # Create a game state and encode it state = pkrs.State.from_seed(n_players=6, button=0, sb=1, bb=2, stake=200.0, seed=42) state_vector = encode_state(state, player_id=0) state_tensor = torch.FloatTensor(state_vector).unsqueeze(0) # Forward pass returns action logits and bet size multiplier with torch.no_grad(): action_logits, bet_size = network(state_tensor) print(f"Action logits (Fold, Check/Call, Raise): {action_logits[0].numpy()}") print(f"Bet size multiplier: {bet_size[0][0].item():.2f}x pot") # Range: 0.1 to 3.0 # Apply softmax for action probabilities probs = torch.softmax(action_logits, dim=1) print(f"Action probabilities: {probs[0].numpy()}") ``` -------------------------------- ### Run Basic Poker GUI Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/scripts/poker_gui_guide.md Launch the poker GUI application from the project root directory. This will open the model selection dialog. ```bash python -m scripts.poker_gui ``` -------------------------------- ### Monitor Training with TensorBoard Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Launches TensorBoard to visualize training logs. Access the dashboard via http://localhost:6006. ```bash tensorboard --logdir=logs Then open `http://localhost:6006`. ``` -------------------------------- ### Configure Game with Models and Parameters Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/scripts/poker_gui_guide.md Launch the poker GUI with a specific folder of models and set custom game parameters such as player position, stake, small blind, and big blind. ```bash python -m scripts.poker_gui --models_folder models_om --position 2 --stake 100 --sb 0.5 --bb 1 ``` -------------------------------- ### Run GUI with Models Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Launch the graphical user interface for playing poker, pointing to the folder where trained models are stored. ```bash python scripts/poker_gui.py --models_folder models/phase1 ``` -------------------------------- ### Load Models from Folder Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/scripts/poker_gui_guide.md Run the poker GUI and load all model files from a specified directory. This is useful for using a collection of pre-trained models. ```bash python -m scripts.poker_gui --models_folder models_mixed_om_v2 ``` -------------------------------- ### Opponent Modeling System Initialization Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initializes the OpponentModelingSystem for tracking opponent actions and generating feature vectors. Configure maximum history per opponent, action/state dimensions, and device. ```python from src.opponent_modeling.opponent_model import OpponentModelingSystem import numpy as np # Initialize opponent modeling system opp_system = OpponentModelingSystem( max_history_per_opponent=20, action_dim=4, state_dim=25, device='cpu' ) # Record a game for an opponent opponent_id = "player_1" action_sequence = [ np.array([0, 0, 1, 0]), # Check/Call encoded np.array([0, 0, 0, 1]), # Large raise encoded np.array([1, 0, 0, 0]), # Fold encoded ] state_contexts = [np.random.randn(25) for _ in range(3)] outcome = 50.0 # Chips won opp_system.record_game(opponent_id, action_sequence, state_contexts, outcome) # Get opponent encoding (64-dim vector) encoding = opp_system.get_opponent_encoding(opponent_id) print(f"Opponent encoding shape: {encoding.shape}") # Get predicted opponent features (20-dim tendency vector) features = opp_system.get_opponent_features(opponent_id) print(f"Opponent features: {features[:5]}...") # First 5 tendencies # Train the opponent modeling system loss = opp_system.train(batch_size=32, epochs=1) print(f"Training loss: {loss:.4f}") ``` -------------------------------- ### DeepCFRAgent Initialization and Usage Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initialize the DeepCFRAgent for a 6-player game, load a trained model, choose an action based on the current state, and save checkpoints. ```python import torch from src.core.deep_cfr import DeepCFRAgent # Initialize agent for 6-player game at position 0 agent = DeepCFRAgent( player_id=0, num_players=6, memory_size=300000, device='cuda' if torch.cuda.is_available() else 'cpu' ) # Load a trained model from checkpoint agent.load_model("models/checkpoint_iter_1000.pt") # Get action during gameplay import pokers as pkrs state = pkrs.State.from_seed( n_players=6, button=0, sb=1, bb=2, stake=200.0, seed=42 ) # Agent chooses action based on trained strategy action = agent.choose_action(state) print(f"Action: {action.action}, Amount: {action.amount if action.action == pkrs.ActionEnum.Raise else 'N/A'}") # Save model checkpoint agent.iteration_count = 1000 agent.save_model("models/my_checkpoint") # Saves as my_checkpoint_iteration_1000.pt ``` -------------------------------- ### Play Against Trained Models (CLI) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Launches an interactive command-line interface to play poker against trained AI models. Customize model directories, patterns, number of models, and game settings. ```bash # Play against models from a directory python scripts/play.py --models-dir models/phase1 # Customize game settings python scripts/play.py \ --models-dir models/mixed \ --model-pattern "checkpoint_*.pt" \ --num-models 5 \ --position 0 \ --stake 200.0 \ --sb 1.0 \ --bb 2.0 # Keep same opponents across games python scripts/play.py \ --models-dir models/phase1 \ --no-shuffle # Enable strict error checking python scripts/play.py \ --models-dir models/phase1 \ --strict \ --verbose ``` -------------------------------- ### Load Specific Model Files Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/scripts/poker_gui_guide.md Run the poker GUI and specify individual model files to use as opponents. Provide the paths to the .pt model files. ```bash python -m scripts.poker_gui --models path/to/model1.pt path/to/model2.pt path/to/model3.pt ``` -------------------------------- ### Opponent Modeling Training (Bash) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initiates experimental training using GRU-based opponent action history encoding for adaptive play. Specify save and log directories. ```bash python -m src.training.train_with_opponent_modeling \ --iterations 1000 \ --traversals 200 \ --save-dir models_om \ --log-dir logs/deepcfr_om ``` -------------------------------- ### Mixed Training with Opponent Modeling Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initiates mixed training with opponent modeling. Specify model directories, training iterations, and save/log locations. ```bash python -m src.training.train_mixed_with_opponent_modeling \ --checkpoint-dir models_om \ --model-prefix "*" \ --iterations 10000 \ --traversals 200 \ --refresh-interval 1000 \ --num-opponents 5 \ --save-dir models_mixed_om \ --log-dir logs/deepcfr_mixed_om ``` -------------------------------- ### Run CLI with Models Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Execute the main play script via the command line, specifying the directory containing trained models. Useful options allow filtering checkpoints, controlling the number of sampled opponents, setting player position, maintaining model consistency across games, and enforcing strict game state validation. ```bash python scripts/play.py --models-dir models/phase1 ``` -------------------------------- ### Self-Play Training (Bash) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initiates self-play training by continuing from a checkpoint and training against a frozen version of itself. Requires a checkpoint. ```bash python -m src.training.train \ --checkpoint models/phase1/checkpoint_iter_1000.pt \ --self-play \ --iterations 2000 \ --traversals 400 \ --log-dir logs/selfplay \ --save-dir models/selfplay ``` -------------------------------- ### Deep CFR Agent with Opponent Modeling Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initializes a Deep CFR agent with opponent modeling capabilities. Record opponent actions during gameplay and use them to inform action choices. Finalize recording at the end of each game. ```python from src.opponent_modeling.deep_cfr_with_opponent_modeling import DeepCFRAgentWithOpponentModeling # Create agent with opponent modeling agent = DeepCFRAgentWithOpponentModeling( player_id=0, num_players=6, memory_size=300000, device='cuda' ) # Record opponent actions during gameplay for modeling import pokers as pkrs state = pkrs.State.from_seed(n_players=6, button=0, sb=1, bb=2, stake=200.0, seed=42) # When opponent acts, record their action opponent_id = 1 action_id = 2 # 0=Fold, 1=Check/Call, 2=Small Raise, 3=Large Raise agent.record_opponent_action(state, action_id, opponent_id) # At end of game, finalize recording agent.end_game_recording(state) # Choose action with opponent modeling action = agent.choose_action(state, opponent_id=opponent_id) ``` -------------------------------- ### Continue Training from Checkpoint (Bash) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Resumes training from a specified checkpoint file, continuing for additional iterations. Requires existing checkpoint. ```bash python -m src.training.train \ --checkpoint models/phase1/checkpoint_iter_1000.pt \ --iterations 1000 \ --traversals 200 \ --log-dir logs/continued \ --save-dir models/continued ``` -------------------------------- ### Train Against Random Opponents Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Initiates Phase 1 training against random opponents. Specify the number of iterations, traversals, and log/save directories. ```python python -m src.training.train --iterations 1000 --traversals 200 --log-dir logs/phase1 --save-dir models/phase1 ``` -------------------------------- ### Visualize Tournament Results Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Generate tournament visualizations by specifying checkpoint files and the number of games to simulate. This helps in analyzing performance across different training stages. ```bash python scripts/visualize_tournament.py \ --checkpoints models/phase1/checkpoint_iter_1000.pt models/selfplay/checkpoint_iter_2000.pt \ --num-games 100 ``` -------------------------------- ### Mixed Checkpoint Training (Python) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Programmatically trains against a mixed pool of checkpoints, specifying parameters for opponent selection, refresh interval, and training duration. ```python from src.training.train import train_with_mixed_checkpoints agent, losses, profits, profits_vs_checkpoints = train_with_mixed_checkpoints( checkpoint_dir="models", training_model_prefix="t_", # Match files like t_mixed_iter_100.pt additional_iterations=10000, traversals_per_iteration=400, save_dir="models/mixed", log_dir="logs/mixed", refresh_interval=1000, # Refresh opponent pool every 1000 iterations num_opponents=5, verbose=False ) print(f"Final profit vs random: {profits[-1]:.2f}") print(f"Final profit vs mixed: {profits_vs_checkpoints[-1]:.2f}") ``` -------------------------------- ### Mixed Training Against a Checkpoint Pool Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Initiates Phase 3 mixed training against a pool of models. Configure checkpoint directory, model prefix, refresh interval, number of opponents, and training parameters. ```python python -m src.training.train \ --mixed \ --checkpoint-dir models \ --model-prefix t_ \ --refresh-interval 1000 \ --num-opponents 5 \ --iterations 10000 \ --traversals 400 \ --log-dir logs/mixed \ --save-dir models/mixed ``` -------------------------------- ### Mixed Opponent-Modeling Training Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Runs mixed training with opponent modeling. Specify checkpoint directory, model prefix, iterations, traversals, refresh interval, and number of opponents. ```python python -m src.training.train_mixed_with_opponent_modeling \ --checkpoint-dir models_om \ --model-prefix "*" \ --iterations 10000 \ --traversals 200 \ --refresh-interval 1000 \ --num-opponents 5 \ --save-dir models_mixed_om \ --log-dir logs/deepcfr_mixed_om ``` -------------------------------- ### Mixed Checkpoint Training (Bash) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Trains against a pool of historical checkpoints, refreshing the opponent pool periodically. Requires a directory of checkpoints. ```bash python -m src.training.train \ --mixed \ --checkpoint-dir models \ --model-prefix t_ \ --refresh-interval 1000 \ --num-opponents 5 \ --iterations 10000 \ --traversals 400 \ --log-dir logs/mixed \ --save-dir models/mixed ``` -------------------------------- ### Continue Training from Checkpoint (Python) Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Programmatically continues training from a saved checkpoint, specifying additional iterations and directories for saving logs and models. ```python from src.training.train import continue_training agent, losses, profits = continue_training( checkpoint_path="models/phase1/checkpoint_iter_1000.pt", additional_iterations=1000, traversals_per_iteration=200, save_dir="models/continued", log_dir="models/continued", verbose=False ) ``` -------------------------------- ### Extended Self-Play Training with 400 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Continues self-play training with an increased traversal count (400) and specifies separate logging and save directories. Use for deeper self-play refinement. ```bash python train.py --checkpoint models/selfplay_checkpoint_iter_2000.pt --self-play --iterations 2000 --traversals 400 --log-dir logs/selfplay2 --save-dir selfplay2 ``` -------------------------------- ### Self-Play Training with 400 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Initiates self-play training using a checkpoint and 400 traversals. This phase aims to develop more sophisticated play against itself. ```bash python train.py --checkpoint models/400/checkpoint_iter_2000.pt --self-play --iterations 2000 --traversals 400 ``` -------------------------------- ### Tournament Visualization Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Runs tournaments between different model checkpoints and generates performance visualizations. Specify checkpoint paths, number of games, output directory, and verbosity. ```bash python scripts/visualize_tournament.py \ --checkpoints models/phase1/checkpoint_iter_1000.pt \ models/selfplay/checkpoint_iter_2000.pt \ models/mixed/checkpoint_iter_5000.pt \ --num-games 100 \ --output-dir tournament_results \ --verbose ``` -------------------------------- ### Self-Play Training Against a Fixed Checkpoint Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Enables Phase 2 self-play training where the model plays against a fixed checkpoint. Adjust iterations, traversals, and directories as needed. ```python python -m src.training.train \ --checkpoint models/phase1/checkpoint_iter_1000.pt \ --self-play \ --iterations 2000 \ --traversals 400 \ --log-dir logs/selfplay \ --save-dir models/selfplay ``` -------------------------------- ### Continue Training From a Checkpoint Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Resumes training from a previously saved checkpoint. Requires specifying the checkpoint path, new iterations, traversals, and log/save directories. ```python python -m src.training.train \ --checkpoint models/phase1/checkpoint_iter_1000.pt \ --iterations 1000 \ --traversals 200 \ --log-dir logs/continued \ --save-dir models/continued ``` -------------------------------- ### Run and Visualize Poker Tournaments Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Executes a tournament between specified model checkpoints and generates visualizations of stack history. Access results data after the tournament. ```python from scripts.visualize_tournament import run_tournament, plot_stack_history # Run tournament between checkpoints checkpoint_paths = [ "models/phase1/checkpoint_iter_1000.pt", "models/selfplay/checkpoint_iter_2000.pt", "models/mixed/checkpoint_iter_5000.pt", ] results_df = run_tournament( checkpoint_paths=checkpoint_paths, num_games=100, device='cuda', blinds=(1.0, 2.0), stake=200.0, verbose=True ) # Generate visualizations plot_stack_history(results_df, output_dir="tournament_results") # Access tournament data print(f"Games played: {len(results_df)}") for i in range(6): final_profit = results_df[f'player_{i}_cumulative_profit'].iloc[-1] print(f"Player {i}: {final_profit:+.2f}") ``` -------------------------------- ### Basic Deep CFR Training Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Initiates basic Deep CFR training for a specified number of iterations and traversals. Logs and model checkpoints are saved. ```bash python -m src.training.train \ --iterations 1000 \ --traversals 200 \ --log-dir logs/phase1 \ --save-dir models/phase1 ``` ```bash python -m src.training.train \ --iterations 500 \ --traversals 100 \ --log-dir logs/debug \ --save-dir models/debug \ --verbose ``` ```bash python -m src.training.train \ --iterations 1000 \ --traversals 200 \ --save-dir models/strict \ --strict ``` -------------------------------- ### Self-Play Training with 100 Traversals Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Conducts self-play training with a lower traversal count (100) for faster iteration cycles. Useful for rapid testing of self-play dynamics. ```bash python train.py --checkpoint models/selfplay_checkpoint_iter_2000.pt --self-play --iterations 2000 --traversals 100 ``` -------------------------------- ### Evaluate Agent Against Checkpoint Opponents Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Loads checkpoint models for opponent agents and evaluates the primary agent's performance against them over a specified number of games. Ensure models are saved in the 'models/selfplay/' directory. ```python opponent_agents = [] for pos in range(6): if pos != 0: opp = DeepCFRAgent(player_id=pos, num_players=6, device='cpu') opp.load_model("models/selfplay/checkpoint_iter_2000.pt") opponent_agents.append(opp) else: opponent_agents.append(None) avg_profit_vs_checkpoints = evaluate_against_checkpoint_agents( agent, opponent_agents, num_games=100 ) print(f"Average profit vs checkpoints: {avg_profit_vs_checkpoints:.2f}") ``` -------------------------------- ### Run All Regression Tests Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Executes all regression tests for the poker engine and training stability using pytest. The -q flag provides quiet output. ```bash # Run all tests python3 -m pytest tests/test_pokers_regressions.py tests/test_training_regressions.py -q ``` -------------------------------- ### Run Specific Test File with Verbose Output Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Executes tests from a specific file ('test_training_regressions.py') with verbose output. This is useful for targeted debugging. ```bash # Run specific test file python3 -m pytest tests/test_training_regressions.py -v ``` -------------------------------- ### Run Regression Tests Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/readme.md Execute targeted regression tests for poker and training stability using pytest. The `-q` flag provides quieter output. These tests cover critical issues like all-in actions, legal actions, self-play, and replay memory consistency. ```bash python3 -m pytest tests/test_pokers_regressions.py tests/test_training_regressions.py -q ``` -------------------------------- ### Mixed Training with Reduced Learning Rate Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Initiates mixed training against a diverse opponent pool with a reduced learning rate (0.00005) and a specified refresh interval for opponents. This phase is crucial for developing robust and generalized poker strategies. ```bash python train.py --mixed --checkpoint-dir selfplay3 --model-prefix selfplay --iterations 20000 --traversals 400 --log-dir logs/mixed --save-dir models/mixed --refresh-interval 1000 ``` -------------------------------- ### Extended Training of 400 Traversal Model Source: https://github.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/blob/main/flagship_models/first/description.md Continues training the model that was previously trained with 400 traversals. Use to deepen strategic understanding. ```bash python train.py --checkpoint models/400/checkpoint_iter_1000.pt --iterations 1000 --traversals 400 --log-dir logs/400 --save-dir models/400 ``` -------------------------------- ### PrioritizedMemory Buffer Operations Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Manage an experience replay buffer with prioritized sampling. Add experiences with automatic or explicit priorities, sample batches with importance sampling weights, and update priorities based on TD-errors. ```python from src.core.deep_cfr import PrioritizedMemory import numpy as np # Create prioritized memory buffer memory = PrioritizedMemory(capacity=100000, alpha=0.6) # Add experience with automatic max priority state_encoding = np.random.randn(145) # State vector opponent_features = np.zeros(20) experience = (state_encoding, opponent_features, 2, 1.5, 0.8) # (state, opp_feat, action_type, bet_size, regret) memory.add(experience) # Add with explicit priority memory.add(experience, priority=2.5) # Sample batch with importance sampling weights batch_size = 128 beta = 0.4 # Importance sampling correction (anneal from 0.4 to 1.0) samples, indices, weights = memory.sample(batch_size, beta=beta) # Update priorities after computing new TD errors for i, idx in enumerate(indices): new_td_error = 0.5 # Computed from training memory.update_priority(idx, new_td_error + 0.01) # Get memory statistics stats = memory.get_memory_stats() print(f"Buffer size: {stats['size']}, Mean priority: {stats['mean']:.4f}") ``` -------------------------------- ### Programmatic Deep CFR Training Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Executes Deep CFR training programmatically, returning the trained agent, losses, and profits. Specify save and log directories. ```python from src.training.train import train_deep_cfr # Programmatic training agent, losses, profits = train_deep_cfr( num_iterations=1000, traversals_per_iteration=200, num_players=6, player_id=0, save_dir="models/phase1", log_dir="logs/phase1", verbose=False ) print(f"Final loss: {losses[-1]:.6f}") print(f"Final avg profit vs random: {profits[-1]:.2f}") ``` -------------------------------- ### Evaluate Agent Against Random Opponents Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Evaluates a trained Deep CFR agent's performance against random opponents over a specified number of games. Loads the agent model from a checkpoint file. ```python from src.training.train import evaluate_against_random, evaluate_against_checkpoint_agents from src.core.deep_cfr import DeepCFRAgent # Load agent agent = DeepCFRAgent(player_id=0, num_players=6, device='cpu') agent.load_model("models/phase1/checkpoint_iter_1000.pt") # Evaluate against random opponents avg_profit = evaluate_against_random(agent, num_games=500, num_players=6) print(f"Average profit vs random: {avg_profit:.2f} per game") ``` -------------------------------- ### Run Pytest with Verbose Output Source: https://context7.com/dberweger2017/deepcfr-texas-no-limit-holdem-6-players/llms.txt Executes tests with verbose output enabled, showing individual test results. This command runs all tests within the 'tests/' directory. ```bash # Run with verbose output python3 -m pytest tests/ -v ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.