(tensor, first_dim=1)
| 132 | |
| 133 | |
| 134 | def renormalize(tensor, first_dim=1): |
| 135 | # normalize the tensor (states) |
| 136 | if first_dim < 0: |
| 137 | first_dim = len(tensor.shape) + first_dim |
| 138 | flat_tensor = tensor.view(*tensor.shape[:first_dim], -1) |
| 139 | max = torch.max(flat_tensor, first_dim, keepdim=True).values |
| 140 | min = torch.min(flat_tensor, first_dim, keepdim=True).values |
| 141 | flat_tensor = (flat_tensor - min) / (max - min) |
| 142 | |
| 143 | return flat_tensor.view(*tensor.shape) |
no outgoing calls
no test coverage detected