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

Update nbeats/sub_modules.py to remove UserWarning #1580

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
25 changes: 14 additions & 11 deletions pytorch_forecasting/models/nbeats/sub_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,19 @@ def __init__(
backcast_linspace, forecast_linspace = linspace(backcast_length, forecast_length, centered=False)

p1, p2 = (thetas_dim // 2, thetas_dim // 2) if thetas_dim % 2 == 0 else (thetas_dim // 2, thetas_dim // 2 + 1)
s1_b = torch.tensor(
[np.cos(2 * np.pi * i * backcast_linspace) for i in self.get_frequencies(p1)], dtype=torch.float32
s1_b = torch.from_numpy(np.array(
[np.cos(2 * np.pi * i * backcast_linspace) for i in self.get_frequencies(p1)], dtype=np.float32),
) # H/2-1
s2_b = torch.tensor(
[np.sin(2 * np.pi * i * backcast_linspace) for i in self.get_frequencies(p2)], dtype=torch.float32
s2_b = torch.from_numpy(np.array(
[np.sin(2 * np.pi * i * backcast_linspace) for i in self.get_frequencies(p2)], dtype=np.float32),
)
self.register_buffer("S_backcast", torch.cat([s1_b, s2_b]))

s1_f = torch.tensor(
[np.cos(2 * np.pi * i * forecast_linspace) for i in self.get_frequencies(p1)], dtype=torch.float32
s1_f = torch.from_numpy(np.array(
[np.cos(2 * np.pi * i * forecast_linspace) for i in self.get_frequencies(p1)], dtype=np.float32),
) # H/2-1
s2_f = torch.tensor(
[np.sin(2 * np.pi * i * forecast_linspace) for i in self.get_frequencies(p2)], dtype=torch.float32
s2_f = torch.from_numpy(np.array(
[np.sin(2 * np.pi * i * forecast_linspace) for i in self.get_frequencies(p2)], dtype=np.float32),
)
self.register_buffer("S_forecast", torch.cat([s1_f, s2_f]))

Expand Down Expand Up @@ -151,10 +151,13 @@ def __init__(
backcast_linspace, forecast_linspace = linspace(backcast_length, forecast_length, centered=True)
norm = np.sqrt(forecast_length / thetas_dim) # ensure range of predictions is comparable to input

coefficients = torch.tensor([backcast_linspace**i for i in range(thetas_dim)], dtype=torch.float32)
coefficients = torch.from_numpy(
np.array([backcast_linspace**i for i in range(thetas_dim)], dtype=np.float32),
)
self.register_buffer("T_backcast", coefficients * norm)

coefficients = torch.tensor([forecast_linspace**i for i in range(thetas_dim)], dtype=torch.float32)
coefficients = torch.from_numpy(
np.array([forecast_linspace**i for i in range(thetas_dim)], dtype=np.float32),
)
self.register_buffer("T_forecast", coefficients * norm)

def forward(self, x) -> Tuple[torch.Tensor, torch.Tensor]:
Expand Down
Loading