Skip to content
Merged
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
18 changes: 18 additions & 0 deletions examples/timeseries/anomaly.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

import torch

import sdm

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

time = torch.arange(200, device=device, dtype=torch.float32)
x = torch.stack([torch.sin(time / 12), torch.cos(time / 20)], dim=-1)
x[140:149] += 3 # Add anomalies.

model = sdm.models.KumoAnomaly(device=device)

# Higher reconstruction error scores indicate more likely anomalies:
score = model(x).numerical.squeeze(-1)
print(score[131:158])
File renamed without changes.
5 changes: 3 additions & 2 deletions sdm/models/kumo/timeseries/anomaly/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,9 @@ def forward(
dim=0,
)

out = out.view(x.size())[:, :R, :D]
out = (out - x[:, :R, :D]).abs().mean(dim=-1)
out = out.view(x.size())[:, :R, :D].clamp(-1e8, 1e8)
x = x[:, :R, :D].clamp(-1e8, 1e8)
out = (out - x).abs().mean(dim=-1).clamp(max=1e8)
return out.view(*B, R)

def reconstruct(
Expand Down
Loading