def train(model, device, dataloader, optimizer):
    '\n    Performs one epoch of training.\n    Order of rooms in building and in data must match otherwise model will fit wrong rooms to data.\n    '
    model.reset_iv()
    model.train()
    model.cooling_policy.eval()
    for layer in model.cooling_policy.parameters():
        layer.requires_grad = False
    num_cols = len(model.building.rooms)
    num_batches = len(dataloader)
    train_loss = 0
    loss_fn = torch.nn.MSELoss()
    for (batch, (time, temp)) in enumerate(dataloader):
        (time, temp) = (time.to(device), temp.to(device))
        time = time.squeeze(0)
        temp = temp.squeeze(0)
        pred = model(time)
        pred = pred.squeeze((- 1))
        loss = loss_fn(pred[:, 2:], temp[:, 0:num_cols])
        train_loss += loss.item()
        model.iv = pred[(- 1), :].unsqueeze(1).detach()
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
    return (train_loss / num_batches)
Performs one epoch of training.
Order of rooms in building and in data must match otherwise model will fit wrong rooms to data.
def train(model, device, dataloader, optimizer):
    '\n    Performs one epoch of training.\n    Order of rooms in building and in data must match otherwise model will fit wrong rooms to data.\n    '
    model.reset_iv()
    model.train()
    model.cooling_policy.eval()
    for layer in model.cooling_policy.parameters():
        layer.requires_grad = False
    num_cols = len(model.building.rooms)
    num_batches = len(dataloader)
    train_loss = 0
    loss_fn = torch.nn.MSELoss()
    for (batch, (time, temp)) in enumerate(dataloader):
        (time, temp) = (time.to(device), temp.to(device))
        time = time.squeeze(0)
        temp = temp.squeeze(0)
        pred = model(time)
        pred = pred.squeeze((- 1))
        loss = loss_fn(pred[:, 2:], temp[:, 0:num_cols])
        train_loss += loss.item()
        model.iv = pred[(- 1), :].unsqueeze(1).detach()
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()
    return (train_loss / num_batches)