Skip to content

Commit 30943c7

Browse files
committed
Simplify Kumo transform schedule and shift dispatch
1 parent d816644 commit 30943c7

3 files changed

Lines changed: 29 additions & 57 deletions

File tree

‎sdm/models/kumo/tabular/recipe.py‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def numerical_processor() -> sp.Sequential:
2222
sp.RobustScale(),
2323
sp.ClipSoft(3.0),
2424
],
25+
sp.RankGaussian(),
2526
method="round_robin",
2627
),
2728
sp.ClipSigma(threshold=4.0),
@@ -31,32 +32,7 @@ def numerical_processor() -> sp.Sequential:
3132
features=[
3233
sp.StypeDispatch(
3334
numerical=[
34-
sp.Cast(torch.float64),
35-
sp.DropConstantColumns(),
36-
# Period 12 preserves the original three-way schedule
37-
# while replacing every fourth view with Gaussian ranks.
38-
sp.Choice(
39-
*[
40-
[
41-
sp.RankGaussian(),
42-
sp.Standardize(),
43-
sp.ClipSigma(threshold=4.0),
44-
]
45-
if i % 4 == 3
46-
else [
47-
sp.Standardize(eps=1e-6),
48-
sp.Clip(-100.0, 100.0),
49-
(
50-
sp.Identity(),
51-
sp.PowerTransform(),
52-
[sp.RobustScale(), sp.ClipSoft(3.0)],
53-
)[i % 3],
54-
sp.ClipSigma(threshold=4.0),
55-
]
56-
for i in range(12)
57-
],
58-
method="round_robin",
59-
),
35+
numerical_processor(),
6036
sp.FlipSign(),
6137
],
6238
categorical=[

‎sdm/processing/categorical/shuffle.py‎

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,27 @@ def _draw_permutations(
6363
n_classes = category.numel()
6464
if n_classes <= 1:
6565
permutation = torch.arange(n_classes, device=device)
66-
elif self.method in ("shift", "balanced_shift"):
67-
if self.method == "balanced_shift":
68-
key = (device, column, n_classes)
69-
remaining = shifts.get(key)
70-
if remaining is None or remaining.numel() == 0:
71-
remaining = torch.randperm(
72-
n_classes,
73-
generator=generator,
74-
device=device,
75-
)
76-
offset = remaining[:1]
77-
shifts[key] = remaining[1:]
78-
else:
79-
offset = torch.randint(
66+
elif self.method == "shift":
67+
offset = torch.randint(
68+
n_classes,
69+
(1,),
70+
generator=generator,
71+
device=device,
72+
)
73+
permutation = (
74+
torch.arange(n_classes, device=device) - offset
75+
) % n_classes
76+
elif self.method == "balanced_shift":
77+
key = (device, column, n_classes)
78+
remaining = shifts.get(key)
79+
if remaining is None or remaining.numel() == 0:
80+
remaining = torch.randperm(
8081
n_classes,
81-
(1,),
8282
generator=generator,
8383
device=device,
8484
)
85+
offset = remaining[:1]
86+
shifts[key] = remaining[1:]
8587
permutation = (
8688
torch.arange(n_classes, device=device) - offset
8789
) % n_classes

‎test/models/kumo/tabular/test_recipe.py‎

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -169,23 +169,17 @@ def test_default_recipe_numerical_schedule(
169169
EnsembleTable.from_table(query, num_members=num_members)
170170
)
171171
for i in range(num_members):
172-
if i % 4 == 3:
173-
processor = sp.Sequential(
172+
processor = sp.Sequential(
173+
sp.Standardize(eps=1e-6),
174+
sp.Clip(-100.0, 100.0),
175+
(
176+
sp.Identity(),
177+
sp.PowerTransform(),
178+
[sp.RobustScale(), sp.ClipSoft(3.0)],
174179
sp.RankGaussian(),
175-
sp.Standardize(),
176-
sp.ClipSigma(threshold=4.0),
177-
)
178-
else:
179-
processor = sp.Sequential(
180-
sp.Standardize(eps=1e-6),
181-
sp.Clip(-100.0, 100.0),
182-
(
183-
sp.Identity(),
184-
sp.PowerTransform(),
185-
[sp.RobustScale(), sp.ClipSoft(3.0)],
186-
)[i % 3],
187-
sp.ClipSigma(threshold=4.0),
188-
)
180+
)[i % 4],
181+
sp.ClipSigma(threshold=4.0),
182+
)
189183
expected = processor.fit_transform(features).numerical.float()
190184
# Independent sign flips are allowed; magnitudes identify each view.
191185
torch.testing.assert_close(

0 commit comments

Comments
 (0)