Views
No views yet
| Mamba-2 SSM | Dictionary-KAN | |
|---|---|---|
| Input shape | (batch, 30, 62) float32 | (batch, 62) float32 |
| Input meaning | 30-day sliding window of features | Single day of features |
| Output shape | (batch, 7) float32 | (batch, 7) float32 |
| Output meaning | 7 log-rates → exp() → counts | 7 log-rates → exp() → counts |
| Output columns | [total, urgent, topic0, topic1, topic2, topic3, topic4] | same |
| Loss | Poisson NLL | Poisson NLL + TV regulariser |
| Params | < 400 k | ~ 41 RBF centres (after DHR) |
| Test MAE (total) | 0.9947 | 193.03 (see note) |
Dictionary-KAN note: The high test MAE reflects variance compounding on extreme weather outliers without Complex Batch Norm. It is a proof-of-concept for interpretability, not the operational forecaster. Use Mamba-2 for production residuals.
1 0 temperature_2m_max (StandardScaler)
2 1 temperature_2m_min (StandardScaler)
3 2 temperature_2m_mean (StandardScaler)
4 3 apparent_temperature_max (StandardScaler)
5 4 apparent_temperature_min (StandardScaler)
6 5 relative_humidity_2m_mean (StandardScaler)
7 6 dew_point_2m_mean (StandardScaler)
8 7 pressure_msl_mean (StandardScaler)
9 8 wind_speed_10m_max (StandardScaler)
10 9 wind_gusts_10m_max (RobustScaler)
1110 cloud_cover_mean (StandardScaler)
1211 shortwave_radiation_sum (StandardScaler)
1312 temp_range (StandardScaler)
1413 precipitation_sum (RobustScaler)
1514 rain_sum (RobustScaler)
1615 snowfall_sum (RobustScaler)
1716 precip_3d (RobustScaler)
1817 precip_7d (RobustScaler)
1918 is_freeze_thaw (binary 0/1)
2019 freeze_thaw_7d (StandardScaler)
2120 freeze_thaw_14d (StandardScaler)
2221 freeze_thaw_30d (StandardScaler)
2322 is_holiday (binary 0/1)
2423 is_nowruz_break (binary 0/1)
2524 is_school_season (binary 0/1)
2625 is_periurban (binary 0/1)
2726 sin_jalali_month (−1 … 1)
2827 cos_jalali_month (−1 … 1)
2928 sin_jalali_week_day (−1 … 1)
3029 cos_jalali_week_day (−1 … 1)
3130 sin_jalali_year_day (−1 … 1)
3231 cos_jalali_year_day (−1 … 1)
3332 sin_wind_dir (−1 … 1)
3433 cos_wind_dir (−1 … 1)
3534 complaint_count_lag_1 (raw count)
3635 complaint_count_lag_2 (raw count)
3736 complaint_count_lag_3 (raw count)
3837 complaint_count_lag_7 (raw count)
3938 urgent_count_lag_1 (raw count)
4039 urgent_count_lag_2 (raw count)
4140 urgent_count_lag_3 (raw count)
4241 urgent_count_lag_7 (raw count)
4342 count_topic_0_lag_1 (raw count)
4443 count_topic_0_lag_7 (raw count)
4544 count_topic_1_lag_1 (raw count)
4645 count_topic_1_lag_7 (raw count)
4746 count_topic_2_lag_1 (raw count)
4847 count_topic_2_lag_7 (raw count)
4948 count_topic_3_lag_1 (raw count)
5049 count_topic_3_lag_7 (raw count)
5150 count_topic_4_lag_1 (raw count)
5251 count_topic_4_lag_7 (raw count)
5352 freeze_thaw_7d (duplicate check → remove)
54… (fill remaining from your matrix)Scaler rule: Fit on train partition only (≤ 2024-03-20). Apply the same frozen parameters to val / test. Never re-fit.
1import torch, torch.nn as nn
2from huggingface_hub import hf_hub_download
3
4# 1. Grab weights
5path = hf_hub_download(
6 repo_id="Kiarash-m0hammadi/qazvin-137-glassbox",
7 filename="best_mamba_model.pt",
8)
9
10# 2. Rebuild architecture (must match training)
11class MambaForecaster(nn.Module):
12 def __init__(self, in_dim=62, d_model=128, n_layers=2, n_targets=7):
13 super().__init__()
14 from mamba_ssm.modules.mamba2 import Mamba2
15 self.enc = nn.Linear(in_dim, d_model)
16 self.blocks = nn.ModuleList([
17 Mamba2(d_model=d_model, d_state=64, d_conv=4,
18 expand=2, headdim=32)
19 for _ in range(n_layers)
20 ])
21 self.head = nn.Sequential(
22 nn.Linear(d_model, d_model // 2), nn.SiLU(),
23 nn.Linear(d_model // 2, n_targets),
24 )
25 def forward(self, x): # x: (B, 30, 62)
26 h = self.enc(x)
27 for b in self.blocks: h = b(h)
28 return torch.clamp(self.head(h[:, -1, :]), -10, 10)
29
30model = MambaForecaster()
31model.load_state_dict(torch.load(path, map_location="cpu"))
32model.eval()
33
34# 3. Run inference
35# x must be (batch, 30, 62) — already scaled
36with torch.no_grad():
37 log_rates = model(x) # (batch, 7)
38 preds = torch.exp(log_rates) # predicted daily counts1# pip install git+https://github.com/Kiarash-m0hammadi/dictionary-kan.git
2from dictionary_kan.model import DictionaryKAN
3from huggingface_hub import hf_hub_download
4
5path = hf_hub_download(
6 repo_id="Kiarash-m0hammadi/qazvin-137-glassbox",
7 filename="best_dkan_model.pt",
8)
9
10model = torch.load(path, map_location="cpu") # full object
11model.eval()
12
13# x must be (batch, 62) — already scaled
14with torch.no_grad():
15 log_rates = torch.clamp(model(x), -10, 10)
16 preds = torch.exp(log_rates)| Index | Topic | Description |
|---|---|---|
| 0 | Asphalt & Roads | Potholes, trenching, surface fatigue |
| 1 | Waste & Sanitation | Bins, sweeping, uncollected refuse |
| 2 | Water & Canal | Pipe bursts, open gutters, dredging |
| 3 | Construction & Obstruction | Illegal builds, sidewalk blockage |
| 4 | Parks & Green Space | Pruning, irrigation, park upkeep |
E = Predicted − Actual
✅ Map silent hotspots where E > +0.02
✅ Feed residuals into spatial-justice audits1@misc{mohammadi_2026_qazvin137,
2 author = {Mohammadi, Kiarash},
3 title = {Qazvin 137 Glass Box Forensic AI},
4 year = {2026},
5 publisher = {Hugging Face},
6 url = {https://huggingface.co/Kiarash-m0hammadi/qazvin-137-glassbox}
7}10.5281/zenodo.21868515