Skip to content

Commit f1b933f

Browse files
committed
Closure is not revertible
1 parent 1e47869 commit f1b933f

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/transforms/closure.jl

+4-22
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ See also [`Remainder`](@ref).
1313
"""
1414
struct Closure <: StatelessFeatureTransform end
1515

16-
isrevertible(::Type{Closure}) = true
16+
isrevertible(::Type{Closure}) = false
1717

1818
assertions(::Closure) = [scitypeassert(Continuous)]
1919

2020
function applyfeat(::Closure, feat, prep)
2121
cols = Tables.columns(feat)
2222
names = Tables.columnnames(cols)
2323

24-
# table as matrix and get the sum acros dims 2
24+
# convert table to matrix
2525
X = Tables.matrix(feat)
26-
S = sum(X, dims=2)
2726

28-
# divides each row by its sum (closure operation)
27+
# divide each row by its sum (closure operation)
28+
S = sum(X, dims=2)
2929
Z = X ./ S
3030

3131
# table with the old columns and the new values
@@ -34,21 +34,3 @@ function applyfeat(::Closure, feat, prep)
3434

3535
newfeat, S
3636
end
37-
38-
function revertfeat(::Closure, newfeat, fcache)
39-
cols = Tables.columns(newfeat)
40-
names = Tables.columnnames(cols)
41-
42-
# table as matrix
43-
Z = Tables.matrix(newfeat)
44-
45-
# retrieve cache
46-
S = fcache
47-
48-
# undo operation
49-
X = Z .* S
50-
51-
# table with original columns
52-
𝒯 = (; zip(names, eachcol(X))...)
53-
𝒯 |> Tables.materializer(newfeat)
54-
end

test/transforms/closure.jl

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "Closure" begin
2-
@test isrevertible(Closure())
2+
@test !isrevertible(Closure())
33

44
a = [2.0, 66.0, 0.0]
55
b = [4.0, 22.0, 2.0]
@@ -8,7 +8,5 @@
88

99
T = Closure()
1010
n, c = apply(T, t)
11-
tₒ = revert(T, n, c)
1211
@test Tables.matrix(n) [0.2 0.4 0.4; 0.66 0.22 0.12; 0.00 0.02 0.98]
13-
@test Tables.matrix(tₒ) Tables.matrix(t)
1412
end

0 commit comments

Comments
 (0)