python/dqn_agent.py
def sample(self):
        """Randomly sample a batch of experiences from memory."""
        experiences = random.sample(self.memory, k=self.batch_size)

        states = torch.from_numpy(
            np.vstack([e.state for e in experiences if e is not None])).float().to(device)
        actions = torch.from_numpy(
            np.vstack([e.action for e in experiences if e is not None])).long().to(device)
        rewards = torch.from_numpy(
            np.vstack([e.reward for e in experiences if e is not None])).float().to(device)
        next_states = torch.from_numpy(np.vstack(
            [e.next_state for e in experiences if e is not None])).float().to(device)
        dones = torch.from_numpy(np.vstack(
            [e.done for e in experiences if e is not None]).astype(np.uint8)).float().to(device)

        return (states, actions, rewards, next_states, dones), None
Randomly sample a batch of experiences from memory.
Randomly sample a batch of experiences from memory.
Randomly sample a batch of experiences from memory .
def sample(self):
        experiences = random.sample(self.memory, k=self.batch_size)
        states = torch.from_numpy(
            np.vstack([e.state for e in experiences if e is not None])).float().to(device)
        actions = torch.from_numpy(
            np.vstack([e.action for e in experiences if e is not None])).long().to(device)
        rewards = torch.from_numpy(
            np.vstack([e.reward for e in experiences if e is not None])).float().to(device)
        next_states = torch.from_numpy(np.vstack(
            [e.next_state for e in experiences if e is not None])).float().to(device)
        dones = torch.from_numpy(np.vstack(
            [e.done for e in experiences if e is not None]).astype(np.uint8)).float().to(device)
        return (states, actions, rewards, next_states, dones), None
def sample ( self ) : experiences = random . sample ( self . memory , k = self . batch_size ) states = torch . from_numpy ( np . vstack ( [ e . state for e in experiences if e is not None ] ) ) . float ( ) . to ( device ) actions = torch . from_numpy ( np . vstack ( [ e . action for e in experiences if e is not None ] ) ) . long ( ) . to ( device ) rewards = torch . from_numpy ( np . vstack ( [ e . reward for e in experiences if e is not None ] ) ) . float ( ) . to ( device ) next_states = torch . from_numpy ( np . vstack ( [ e . next_state for e in experiences if e is not None ] ) ) . float ( ) . to ( device ) dones = torch . from_numpy ( np . vstack ( [ e . done for e in experiences if e is not None ] ) . astype ( np . uint8 ) ) . float ( ) . to ( device ) return ( states , actions , rewards , next_states , dones ) , None
Randomly sample a batch of experiences from memory.
Randomly sample a batch of experiences from memory .
"""Randomly sample a batch of experiences from memory."""
self