Skip to content

Commit 1e47869

Browse files
committed
Undo changes in LogRatio because Closure is not revertible
1 parent 6574280 commit 1e47869

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

src/transforms/logratio.jl

+8-12
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ function applyfeat(transform::LogRatio, feat, prep)
2626
names = Tables.columnnames(cols)
2727
vars = collect(names)
2828

29-
# perform closure for full revertibility
30-
cfeat, ccache = apply(Closure(), feat)
31-
3229
# reference variable
3330
rvar = refvar(transform, vars)
3431
_assert(rvar vars, "invalid reference variable")
@@ -41,9 +38,9 @@ function applyfeat(transform::LogRatio, feat, prep)
4138
pfeat = if perm
4239
popat!(vars, rind)
4340
push!(vars, rvar)
44-
cfeat |> Select(vars)
41+
feat |> Select(vars)
4542
else
46-
cfeat
43+
feat
4744
end
4845

4946
# apply transform
@@ -57,20 +54,22 @@ function applyfeat(transform::LogRatio, feat, prep)
5754
𝒯 = (; zip(newnames, eachcol(Y))...)
5855
newfeat = 𝒯 |> Tables.materializer(feat)
5956

60-
newfeat, (ccache, perm, rind, vars)
57+
newfeat, (perm, rind, vars)
6158
end
6259

6360
function revertfeat(transform::LogRatio, newfeat, fcache)
6461
# retrieve cache
65-
ccache, perm, rind, vars = fcache
62+
perm, rind, vars = fcache
6663

6764
# revert transform
6865
Y = Tables.matrix(newfeat)
6966
X = revertmatrix(transform, Y)
67+
68+
# reinsert variable names
7069
pfeat = (; zip(vars, eachcol(X))...)
7170

7271
# revert the permutation if necessary
73-
cfeat = if perm
72+
feat = if perm
7473
n = length(vars)
7574
inds = collect(1:(n - 1))
7675
insert!(inds, rind, n)
@@ -79,11 +78,8 @@ function revertfeat(transform::LogRatio, newfeat, fcache)
7978
pfeat
8079
end
8180

82-
# revert closure for full revertibility
83-
𝒯 = revert(Closure(), cfeat, ccache)
84-
8581
# return same table type
86-
𝒯 |> Tables.materializer(newfeat)
82+
feat |> Tables.materializer(newfeat)
8783
end
8884

8985
# ----------------

test/transforms/logratio.jl

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
@test Tables.schema(n).names == (:ARL1, :ARL2)
1414
@test n == t |> ALR(:c)
1515
r = revert(T, n, c)
16-
@test Tables.matrix(r) Tables.matrix(t)
16+
@test all(x -> 0 x 1, Tables.matrix(r))
1717

1818
T = CLR()
1919
n, c = apply(T, t)
2020
@test Tables.schema(n).names == (:CLR1, :CLR2, :CLR3)
2121
r = revert(T, n, c)
22-
@test Tables.matrix(r) Tables.matrix(t)
22+
@test all(x -> 0 x 1, Tables.matrix(r))
2323

2424
T = ILR()
2525
n, c = apply(T, t)
2626
@test Tables.schema(n).names == (:ILR1, :ILR2)
2727
@test n == t |> ILR(:c)
2828
r = revert(T, n, c)
29-
@test Tables.matrix(r) Tables.matrix(t)
29+
@test all(x -> 0 x 1, Tables.matrix(r))
3030

3131
a = [1.0, 0.0, 1.0]
3232
b = [2.0, 2.0, 2.0]
@@ -40,9 +40,9 @@
4040
n2, c2 = apply(T, t2)
4141
r2 = revert(T, n2, c2)
4242
@test n1 == n2
43-
@test Tables.matrix(r1) Tables.matrix(t1)
43+
@test all(x -> 0 x 1, Tables.matrix(r1))
4444
@test Tables.schema(r1).names == (:a, :c, :b)
45-
@test Tables.matrix(r2) Tables.matrix(t2)
45+
@test all(x -> 0 x 1, Tables.matrix(r2))
4646
@test Tables.schema(r2).names == (:c, :a, :b)
4747

4848
T = ILR(:c)
@@ -51,8 +51,8 @@
5151
n2, c2 = apply(T, t2)
5252
r2 = revert(T, n2, c2)
5353
@test n1 == n2
54-
@test Tables.matrix(r1) Tables.matrix(t1)
54+
@test all(x -> 0 x 1, Tables.matrix(r1))
5555
@test Tables.schema(r1).names == (:a, :c, :b)
56-
@test Tables.matrix(r2) Tables.matrix(t2)
56+
@test all(x -> 0 x 1, Tables.matrix(r2))
5757
@test Tables.schema(r2).names == (:c, :a, :b)
5858
end

0 commit comments

Comments
 (0)