import torch
import torch.nn as nn


class Model(nn.Module):
    def __init__(self, gamma):
        super(Model, self).__init__()
        self.gamma = gamma

    def forward(self, values: torch.Tensor, rewards: torch.Tensor, next_values: torch.Tensor,
                dones: torch.Tensor) -> torch.Tensor:
        td_target = rewards + self.gamma * next_values * (1 - dones)
        td_error = values - td_target
        loss = (td_error ** 2).mean()
        return loss


batch_size = 32


def get_inputs():
    values = torch.randn(batch_size)
    rewards = torch.randn(batch_size)
    next_values = torch.randn(batch_size)
    dones = torch.randint(0, 2, (batch_size,)).float()
    return [values, rewards, next_values, dones]


def get_init_inputs():
    gamma = torch.tensor(0.99)
    return [gamma]