def a2c_error(data: namedtuple) -> namedtuple:
    """
    **Overview**:
        Implementation of A2C (Advantage Actor-Critic) <link https://arxiv.org/pdf/1602.01783.pdf link>
    """
    # Unpack data: $$<\pi(a|s), a, V(s), A^{\pi}(s, a), G_t, w>$$
    logit, action, value, adv, return_, weight = data
    # Prepare weight for default cases.
    if weight is None:
        weight = torch.ones_like(value)
    # Prepare policy distribution from logit and get log propability.
    dist = torch.distributions.categorical.Categorical(logits=logit)
    logp = dist.log_prob(action)
    # Policy loss: $$- \frac 1 N \sum_{n=1}^{N} log(\pi(a^n|s^n)) A^{\pi}(s^n, a^n)$$
    policy_loss = -(logp * adv * weight).mean()
    # Value loss: $$\frac 1 N \sum_{n=1}^{N} (G_t^n - V(s^n))^2$$
    value_loss = (F.mse_loss(return_, value, reduction='none') * weight).mean()
    # Entropy bonus: $$\frac 1 N \sum_{n=1}^{N} \sum_{a^n}\pi(a^n|s^n) log(\pi(a^n|s^n))$$
    # P.S. the final loss is ``policy_loss + value_weight * value_loss - entropy_weight * entropy_loss`` .
    entropy_loss = (dist.entropy() * weight).mean()
    # Return the concrete loss items.
    return a2c_loss(policy_loss, value_loss, entropy_loss)

    **Overview**:
        Implementation of A2C (Advantage Actor-Critic) <link https://arxiv.org/pdf/1602.01783.pdf link>
    
chapter1_overview/a2c.py