Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix float errors #842

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions pytorch_forecasting/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1103,10 +1103,14 @@ def to_quantiles(self, y_pred: torch.Tensor, quantiles: List[float] = None, n_sa
quantiles = self.quantiles
try:
distribution = self.map_x_to_distribution(y_pred)
quantiles = distribution.icdf(torch.tensor(quantiles, device=y_pred.device)[:, None, None]).permute(1, 2, 0)
quantiles = distribution.icdf(
torch.tensor(quantiles, device=y_pred.device, dtype=torch.float64)[:, None, None]
).permute(1, 2, 0)
except NotImplementedError: # resort to derive quantiles empirically
samples = torch.sort(self.sample(y_pred, n_samples), -1).values
quantiles = torch.quantile(samples, torch.tensor(quantiles, device=samples.device), dim=2).permute(1, 2, 0)
quantiles = torch.quantile(
samples, torch.tensor(quantiles, device=samples.device, dtype=torch.float64), dim=2
).permute(1, 2, 0)
return quantiles


Expand Down
2 changes: 1 addition & 1 deletion pytorch_forecasting/models/deepar/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def decode_one(
hidden_state,
):
x = input_vector[:, [idx]]
x[:, 0, target_pos] = lagged_targets[-1]
x[:, 0, target_pos] = lagged_targets[-1].float()
for lag, lag_positions in lagged_target_positions.items():
if idx > lag:
x[:, 0, lag_positions] = lagged_targets[-lag]
Expand Down