From 4078948dddf224030c9d2fc7eab9e16c1f21fd0c Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Mon, 6 Nov 2023 17:57:48 -0300 Subject: [PATCH 1/8] Use the 'InverseFunctions.inverse' function in Functional transform --- Project.toml | 4 +- src/TableTransforms.jl | 5 ++- src/transforms/functional.jl | 74 ++++++++++++------------------------ test/shows.jl | 2 +- 4 files changed, 31 insertions(+), 54 deletions(-) diff --git a/Project.toml b/Project.toml index a887793c..f43e0d96 100644 --- a/Project.toml +++ b/Project.toml @@ -10,6 +10,7 @@ CoDa = "5900dafe-f573-5c72-b367-76665857777b" ColumnSelectors = "9cc86067-7e36-4c61-b350-1ac9833d277f" DataScienceTraits = "6cb2f572-2d2b-4ba6-bdb3-e710fa044d6c" Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f" +InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" NelderMead = "2f6b4ddb-b4ff-44c0-b59b-2ab99302f970" PrettyTables = "08abe8d2-0d0c-5749-adfa-8a2ac140af0d" @@ -28,6 +29,7 @@ CoDa = "1.2" ColumnSelectors = "0.1" DataScienceTraits = "0.1" Distributions = "0.25" +InverseFunctions = "0.1" LinearAlgebra = "1.9" NelderMead = "0.4" PrettyTables = "2" @@ -36,6 +38,6 @@ Statistics = "1.9" StatsBase = "0.33, 0.34" Tables = "1.6" Transducers = "0.4" -TransformsBase = "1.2" +TransformsBase = "1.3" Unitful = "1.17" julia = "1.9" diff --git a/src/TableTransforms.jl b/src/TableTransforms.jl index 4ed691e8..eb801ffd 100644 --- a/src/TableTransforms.jl +++ b/src/TableTransforms.jl @@ -21,13 +21,14 @@ using ColumnSelectors: AllSelector, Column, selector, selectsingle using DataScienceTraits: SciType, Continuous, Categorical, coerce using Unitful: AbstractQuantity, AffineQuantity, AffineUnits, Units using Distributions: ContinuousUnivariateDistribution, Normal +using InverseFunctions: inverse as invfun, NoInverse using StatsBase: AbstractWeights, Weights, sample using Transducers: tcollect using NelderMead: optimise import Distributions: quantile, cdf -import TransformsBase: assertions, isrevertible, preprocess -import TransformsBase: apply, revert, reapply +import TransformsBase: assertions, isrevertible, isinvertible, preprocess +import TransformsBase: apply, revert, reapply, inverse include("assertions.jl") include("tabletraits.jl") diff --git a/src/transforms/functional.jl b/src/transforms/functional.jl index a492c132..495db33e 100644 --- a/src/transforms/functional.jl +++ b/src/transforms/functional.jl @@ -3,13 +3,13 @@ # ------------------------------------------------------------------ """ - Functional(func) + Functional(fun) -The transform that applies a `func` elementwise. +The transform that applies a `fun` elementwise. - Functional(col₁ => func₁, col₂ => func₂, ..., colₙ => funcₙ) + Functional(col₁ => fun₁, col₂ => fun₂, ..., colₙ => funₙ) -Apply the corresponding `funcᵢ` function to each `colᵢ` column. +Apply the corresponding `funᵢ` function to each `colᵢ` column. # Examples @@ -23,49 +23,39 @@ Functional("a" => cos, "b" => sin) """ struct Functional{S<:ColumnSelector,F} <: StatelessFeatureTransform selector::S - func::F + fun::F end -Functional(func) = Functional(AllSelector(), func) +Functional(fun) = Functional(AllSelector(), fun) Functional(pairs::Pair{C}...) where {C<:Column} = Functional(selector(first.(pairs)), last.(pairs)) Functional() = throw(ArgumentError("cannot create Functional transform without arguments")) -# known invertible functions -inverse(::typeof(log)) = exp -inverse(::typeof(exp)) = log -inverse(::typeof(cos)) = acos -inverse(::typeof(acos)) = cos -inverse(::typeof(sin)) = asin -inverse(::typeof(asin)) = sin -inverse(::typeof(cosd)) = acosd -inverse(::typeof(acosd)) = cosd -inverse(::typeof(sind)) = asind -inverse(::typeof(asind)) = sind -inverse(::typeof(identity)) = identity +isrevertible(transform::Functional) = isinvertible(transform) -# fallback to nothing -inverse(::Any) = nothing +_hasinverse(f) = !(invfun(f) isa NoInverse) -isrevertible(transform::Functional{AllSelector}) = !isnothing(inverse(transform.func)) +isinvertible(transform::Functional{AllSelector}) = _hasinverse(transform.fun) +isinvertible(transform::Functional) = all(_hasinverse, transform.fun) -isrevertible(transform::Functional) = all(!isnothing, inverse.(transform.func)) +inverse(transform::Functional{AllSelector}) = Functional(transform.selector, invfun(transform.fun)) +inverse(transform::Functional) = Functional(transform.selector, invfun.(transform.fun)) -_funcdict(func, names) = Dict(nm => func for nm in names) -_funcdict(func::Tuple, names) = Dict(names .=> func) +_fundict(fun, names) = Dict(nm => fun for nm in names) +_fundict(funs::Tuple, names) = Dict(names .=> funs) function applyfeat(transform::Functional, feat, prep) cols = Tables.columns(feat) names = Tables.columnnames(cols) snames = transform.selector(names) - funcs = _funcdict(transform.func, snames) + fundict = _fundict(transform.fun, snames) - columns = map(names) do nm - x = Tables.getcolumn(cols, nm) - if nm ∈ snames - func = funcs[nm] - y = func.(x) + columns = map(names) do name + x = Tables.getcolumn(cols, name) + if name ∈ snames + fun = fundict[name] + y = map(fun, x) else y = x end @@ -74,27 +64,11 @@ function applyfeat(transform::Functional, feat, prep) 𝒯 = (; zip(names, columns)...) newfeat = 𝒯 |> Tables.materializer(feat) - return newfeat, (snames, funcs) + + newfeat, nothing end function revertfeat(transform::Functional, newfeat, fcache) - cols = Tables.columns(newfeat) - names = Tables.columnnames(cols) - - snames, funcs = fcache - - columns = map(names) do nm - y = Tables.getcolumn(cols, nm) - if nm ∈ snames - func = funcs[nm] - invfunc = inverse(func) - x = invfunc.(y) - else - x = y - end - x - end - - 𝒯 = (; zip(names, columns)...) - 𝒯 |> Tables.materializer(newfeat) + ofeat, _ = applyfeat(inverse(transform), newfeat, nothing) + ofeat end diff --git a/test/shows.jl b/test/shows.jl index 62bcfb4b..675aa421 100644 --- a/test/shows.jl +++ b/test/shows.jl @@ -328,7 +328,7 @@ @test iostr == """ Functional transform ├─ selector = all - └─ func = sin""" + └─ fun = sin""" end @testset "EigenAnalysis" begin From 2eb29b3f089ee671ef88a421c9cbd383507efc8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Mon, 6 Nov 2023 18:01:29 -0300 Subject: [PATCH 2/8] Update src/TableTransforms.jl --- src/TableTransforms.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TableTransforms.jl b/src/TableTransforms.jl index eb801ffd..831b13f6 100644 --- a/src/TableTransforms.jl +++ b/src/TableTransforms.jl @@ -27,8 +27,8 @@ using Transducers: tcollect using NelderMead: optimise import Distributions: quantile, cdf -import TransformsBase: assertions, isrevertible, isinvertible, preprocess -import TransformsBase: apply, revert, reapply, inverse +import TransformsBase: assertions, isrevertible, isinvertible +import TransformsBase: apply, revert, reapply, preprocess, inverse include("assertions.jl") include("tabletraits.jl") From 7467e90393cd402592cdb0e6201a739b63372737 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 7 Nov 2023 08:46:39 -0300 Subject: [PATCH 3/8] Update tests --- test/metadata.jl | 10 ++-- test/shows.jl | 18 +++---- test/transforms/functional.jl | 91 ++++++++++++----------------------- 3 files changed, 46 insertions(+), 73 deletions(-) diff --git a/test/metadata.jl b/test/metadata.jl index dc8838e5..e46fca07 100644 --- a/test/metadata.jl +++ b/test/metadata.jl @@ -24,7 +24,7 @@ mtₒ = revert(T, mn, mc) @test mtₒ == mt - T = Functional(sin) + T = Functional(exp) mn, mc = apply(T, mt) tn, tc = apply(T, t) @test mn.meta == m @@ -33,7 +33,7 @@ @test mtₒ.meta == mt.meta @test Tables.matrix(mtₒ.table) ≈ Tables.matrix(mt.table) - T = (Functional(sin) → MinMax()) ⊔ Center() + T = (Functional(exp) → MinMax()) ⊔ Center() mn, mc = apply(T, mt) tn, tc = apply(T, t) @test mn.meta == m @@ -68,7 +68,7 @@ mtₒ = revert(T, mn, mc) @test mtₒ == mt - T = Functional(cos) + T = Functional(exp) mn, mc = apply(T, mt) tn, tc = apply(T, t) @test mn.meta == VarMeta(m.data .+ 2) @@ -79,7 +79,7 @@ # first revertible branch has two transforms, # so metadata is increased by 2 + 2 = 4 - T = (Functional(sin) → MinMax()) ⊔ Center() + T = (Functional(exp) → MinMax()) ⊔ Center() mn, mc = apply(T, mt) tn, tc = apply(T, t) @test mn.meta == VarMeta(m.data .+ 4) @@ -90,7 +90,7 @@ # first revertible branch has one transform, # so metadata is increased by 2 - T = Center() ⊔ (Functional(sin) → MinMax()) + T = Center() ⊔ (Functional(exp) → MinMax()) mn, mc = apply(T, mt) tn, tc = apply(T, t) @test mn.meta == VarMeta(m.data .+ 2) diff --git a/test/shows.jl b/test/shows.jl index 675aa421..bf0d504f 100644 --- a/test/shows.jl +++ b/test/shows.jl @@ -317,18 +317,18 @@ end @testset "Functional" begin - T = Functional(sin) + T = Functional(log) # compact mode iostr = sprint(show, T) - @test iostr == "Functional(all, sin)" + @test iostr == "Functional(all, log)" # full mode iostr = sprint(show, MIME("text/plain"), T) @test iostr == """ Functional transform ├─ selector = all - └─ fun = sin""" + └─ fun = log""" end @testset "EigenAnalysis" begin @@ -419,12 +419,12 @@ @testset "ParallelTableTransform" begin t1 = Scale(low=0.3, high=0.6) t2 = EigenAnalysis(:VDV) - t3 = Functional(cos) + t3 = Functional(exp) pipeline = t1 ⊔ t2 ⊔ t3 # compact mode iostr = sprint(show, pipeline) - @test iostr == "Scale(all, 0.3, 0.6) ⊔ EigenAnalysis(:VDV, nothing, 1.0) ⊔ Functional(all, cos)" + @test iostr == "Scale(all, 0.3, 0.6) ⊔ EigenAnalysis(:VDV, nothing, 1.0) ⊔ Functional(all, exp)" # full mode iostr = sprint(show, MIME("text/plain"), pipeline) @@ -432,18 +432,18 @@ ParallelTableTransform ├─ Scale(all, 0.3, 0.6) ├─ EigenAnalysis(:VDV, nothing, 1.0) - └─ Functional(all, cos)""" + └─ Functional(all, exp)""" # parallel and sequential f1 = ZScore() f2 = Scale() - f3 = Functional(cos) + f3 = Functional(exp) f4 = Interquartile() pipeline = (f1 → f2) ⊔ (f3 → f4) # compact mode iostr = sprint(show, pipeline) - @test iostr == "ZScore(all) → Scale(all, 0.25, 0.75) ⊔ Functional(all, cos) → Scale(all, 0.25, 0.75)" + @test iostr == "ZScore(all) → Scale(all, 0.25, 0.75) ⊔ Functional(all, exp) → Scale(all, 0.25, 0.75)" # full mode iostr = sprint(show, MIME("text/plain"), pipeline) @@ -453,7 +453,7 @@ │ ├─ ZScore(all) │ └─ Scale(all, 0.25, 0.75) └─ SequentialTransform - ├─ Functional(all, cos) + ├─ Functional(all, exp) └─ Scale(all, 0.25, 0.75)""" end end diff --git a/test/transforms/functional.jl b/test/transforms/functional.jl index 3054603b..69f46cae 100644 --- a/test/transforms/functional.jl +++ b/test/transforms/functional.jl @@ -1,41 +1,21 @@ @testset "Functional" begin - x = π * rand(100) - y = π * rand(100) + x = rand(0:0.001:1, 100) + y = rand(0:0.001:1, 100) t = Table(; x, y) - T = Functional(cos) - n, c = apply(T, t) - @test all(x -> -1 ≤ x ≤ 1, n.x) - @test all(y -> -1 ≤ y ≤ 1, n.y) - tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - - x = 2 * (rand(100) .- 0.5) - y = 2 * (rand(100) .- 0.5) - t = Table(; x, y) - T = Functional(acos) - n, c = apply(T, t) - @test all(x -> 0 ≤ x ≤ π, n.x) - @test all(y -> 0 ≤ y ≤ π, n.y) - tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - - x = π * (rand(100) .- 0.5) - y = π * (rand(100) .- 0.5) - t = Table(; x, y) - T = Functional(sin) + T = Functional(exp) n, c = apply(T, t) - @test all(x -> -1 ≤ x ≤ 1, n.x) - @test all(y -> -1 ≤ y ≤ 1, n.y) + @test all(x -> 1 ≤ x ≤ ℯ, n.x) + @test all(y -> 1 ≤ y ≤ ℯ, n.y) tₒ = revert(T, n, c) @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - x = 2 * (rand(100) .- 0.5) - y = 2 * (rand(100) .- 0.5) + x = rand(1:0.001:ℯ, 100) + y = rand(1:0.001:ℯ, 100) t = Table(; x, y) - T = Functional(asin) + T = Functional(log) n, c = apply(T, t) - @test all(x -> -π / 2 ≤ x ≤ π / 2, n.x) - @test all(y -> -π / 2 ≤ y ≤ π / 2, n.y) + @test all(x -> 0 ≤ x ≤ 1, n.x) + @test all(y -> 0 ≤ y ≤ 1, n.y) tₒ = revert(T, n, c) @test Tables.matrix(t) ≈ Tables.matrix(tₒ) @@ -71,61 +51,54 @@ @test !isrevertible(T) # apply functions to specific columns - x = π * rand(100) - y = 2 * (rand(100) .- 0.5) + x = rand(0:0.001:1, 100) + y = rand(1:0.001:ℯ, 100) z = x + y t = Table(; x, y, z) - T = Functional(1 => cos, 2 => acos) + + T = Functional(1 => exp, 2 => log) n, c = apply(T, t) - @test all(x -> -1 ≤ x ≤ 1, n.x) - @test all(y -> 0 ≤ y ≤ π, n.y) + @test all(x -> 1 ≤ x ≤ ℯ, n.x) + @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - x = π * rand(100) - y = π * (rand(100) .- 0.5) - z = x + y - t = Table(; x, y, z) - T = Functional(:x => cos, :y => sin) + T = Functional(:x => exp, :y => log) n, c = apply(T, t) - @test all(x -> -1 ≤ x ≤ 1, n.x) - @test all(y -> -1 ≤ y ≤ 1, n.y) + @test all(x -> 1 ≤ x ≤ ℯ, n.x) + @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - x = 2 * (rand(100) .- 0.5) - y = 2 * (rand(100) .- 0.5) - z = x + y - t = Table(; x, y, z) - T = Functional("x" => acos, "y" => asin) + T = Functional("x" => exp, "y" => log) n, c = apply(T, t) - @test all(x -> 0 ≤ x ≤ π, n.x) - @test all(y -> -π / 2 ≤ y ≤ π / 2, n.y) + @test all(x -> 1 ≤ x ≤ ℯ, n.x) + @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) @test Tables.matrix(t) ≈ Tables.matrix(tₒ) - T = Functional(1 => cos, 2 => sin) + T = Functional(1 => log, 2 => exp) @test isrevertible(T) - T = Functional(:x => cos, :y => sin) + T = Functional(:x => log, :y => exp) @test isrevertible(T) - T = Functional("x" => cos, "y" => sin) + T = Functional("x" => log, "y" => exp) @test isrevertible(T) - T = Functional(1 => abs, 2 => sin) + T = Functional(1 => abs, 2 => log) @test !isrevertible(T) - T = Functional(:x => abs, :y => sin) + T = Functional(:x => abs, :y => log) @test !isrevertible(T) - T = Functional("x" => abs, "y" => sin) + T = Functional("x" => abs, "y" => log) @test !isrevertible(T) # row table - x = π * rand(100) - y = π * rand(100) + x = rand(0:0.001:1, 100) + y = rand(0:0.001:1, 100) t = Table(; x, y) rt = Tables.rowtable(t) - T = Functional(cos) + T = Functional(exp) n, c = apply(T, rt) @test Tables.isrowtable(n) rtₒ = revert(T, n, c) @@ -137,7 +110,7 @@ T = Functional(Polynomial(1, 2, 3)) n, c = apply(T, t) @test_throws AssertionError revert(T, n, c) - T = Functional(:x => abs, :y => sin) + T = Functional(:x => abs, :y => log) n, c = apply(T, t) @test_throws AssertionError revert(T, n, c) end From 9f7aec6c0aae82aad2fb9884e065ed2c19438b5c Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 7 Nov 2023 08:52:36 -0300 Subject: [PATCH 4/8] Update docstring --- src/transforms/functional.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transforms/functional.jl b/src/transforms/functional.jl index 495db33e..1fa67edb 100644 --- a/src/transforms/functional.jl +++ b/src/transforms/functional.jl @@ -14,11 +14,11 @@ Apply the corresponding `funᵢ` function to each `colᵢ` column. # Examples ```julia -Functional(cos) -Functional(sin) -Functional(1 => cos, 2 => sin) -Functional(:a => cos, :b => sin) -Functional("a" => cos, "b" => sin) +Functional(exp) +Functional(log) +Functional(1 => exp, 2 => log) +Functional(:a => exp, :b => log) +Functional("a" => exp, "b" => log) ``` """ struct Functional{S<:ColumnSelector,F} <: StatelessFeatureTransform From d738591c50bea331e1bcb20a84c5cf88c83e659c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlio=20Hoffimann?= Date: Tue, 7 Nov 2023 08:57:02 -0300 Subject: [PATCH 5/8] Update src/TableTransforms.jl --- src/TableTransforms.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TableTransforms.jl b/src/TableTransforms.jl index 831b13f6..c94f4f92 100644 --- a/src/TableTransforms.jl +++ b/src/TableTransforms.jl @@ -21,7 +21,7 @@ using ColumnSelectors: AllSelector, Column, selector, selectsingle using DataScienceTraits: SciType, Continuous, Categorical, coerce using Unitful: AbstractQuantity, AffineQuantity, AffineUnits, Units using Distributions: ContinuousUnivariateDistribution, Normal -using InverseFunctions: inverse as invfun, NoInverse +using InverseFunctions: NoInverse, inverse as invfun using StatsBase: AbstractWeights, Weights, sample using Transducers: tcollect using NelderMead: optimise From 150ee4440fcb9b2ee36266c74685b40fbef74832 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 7 Nov 2023 08:58:06 -0300 Subject: [PATCH 6/8] Update code --- src/transforms/functional.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/transforms/functional.jl b/src/transforms/functional.jl index 1fa67edb..2169b41e 100644 --- a/src/transforms/functional.jl +++ b/src/transforms/functional.jl @@ -42,14 +42,14 @@ isinvertible(transform::Functional) = all(_hasinverse, transform.fun) inverse(transform::Functional{AllSelector}) = Functional(transform.selector, invfun(transform.fun)) inverse(transform::Functional) = Functional(transform.selector, invfun.(transform.fun)) -_fundict(fun, names) = Dict(nm => fun for nm in names) -_fundict(funs::Tuple, names) = Dict(names .=> funs) +_fundict(transform::Functional{AllSelector}, names) = Dict(nm => transform.fun for nm in names) +_fundict(transform::Functional, names) = Dict(zip(names, transform.fun)) function applyfeat(transform::Functional, feat, prep) cols = Tables.columns(feat) names = Tables.columnnames(cols) snames = transform.selector(names) - fundict = _fundict(transform.fun, snames) + fundict = _fundict(transform, snames) columns = map(names) do name x = Tables.getcolumn(cols, name) From 51f3c2ca0314273819f7076c0e927cdf8333b172 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 7 Nov 2023 09:07:15 -0300 Subject: [PATCH 7/8] Update tests --- test/transforms/functional.jl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/test/transforms/functional.jl b/test/transforms/functional.jl index 69f46cae..743586f8 100644 --- a/test/transforms/functional.jl +++ b/test/transforms/functional.jl @@ -7,7 +7,7 @@ @test all(x -> 1 ≤ x ≤ ℯ, n.x) @test all(y -> 1 ≤ y ≤ ℯ, n.y) tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test Tables.matrix(tₒ) ≈ Tables.matrix(t) x = rand(1:0.001:ℯ, 100) y = rand(1:0.001:ℯ, 100) @@ -17,21 +17,19 @@ @test all(x -> 0 ≤ x ≤ 1, n.x) @test all(y -> 0 ≤ y ≤ 1, n.y) tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test Tables.matrix(tₒ) ≈ Tables.matrix(t) - x = rand(Normal(0, 25), 100) - y = x + rand(Normal(10, 2), 100) + # identity + x = rand(100) + y = x + rand(100) t = Table(; x, y) - T = Functional(exp) + + T = Functional(identity) n, c = apply(T, t) - @test all(>(0), n.x) - @test all(>(0), n.y) + @test t == n tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test tₒ == t - x = rand(Normal(0, 25), 100) - y = x + rand(Normal(10, 2), 100) - t = Table(; x, y) T = Functional(x -> x) n, c = apply(T, t) @test t == n @@ -62,7 +60,7 @@ @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test Tables.matrix(tₒ) ≈ Tables.matrix(t) T = Functional(:x => exp, :y => log) n, c = apply(T, t) @@ -70,7 +68,7 @@ @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test Tables.matrix(tₒ) ≈ Tables.matrix(t) T = Functional("x" => exp, "y" => log) n, c = apply(T, t) @@ -78,7 +76,7 @@ @test all(y -> 0 ≤ y ≤ 1, n.y) @test t.z == n.z tₒ = revert(T, n, c) - @test Tables.matrix(t) ≈ Tables.matrix(tₒ) + @test Tables.matrix(tₒ) ≈ Tables.matrix(t) T = Functional(1 => log, 2 => exp) @test isrevertible(T) @@ -102,7 +100,7 @@ n, c = apply(T, rt) @test Tables.isrowtable(n) rtₒ = revert(T, n, c) - @test Tables.matrix(rt) ≈ Tables.matrix(rtₒ) + @test Tables.matrix(rtₒ) ≈ Tables.matrix(rt) # throws @test_throws ArgumentError Functional() From 09f1e0afd379f87a8a5dffc75a0e5f2d5c288740 Mon Sep 17 00:00:00 2001 From: Elias Carvalho Date: Tue, 7 Nov 2023 09:15:20 -0300 Subject: [PATCH 8/8] Update code --- src/transforms/functional.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/transforms/functional.jl b/src/transforms/functional.jl index 2169b41e..00815bb8 100644 --- a/src/transforms/functional.jl +++ b/src/transforms/functional.jl @@ -55,11 +55,10 @@ function applyfeat(transform::Functional, feat, prep) x = Tables.getcolumn(cols, name) if name ∈ snames fun = fundict[name] - y = map(fun, x) + map(fun, x) else - y = x + x end - y end 𝒯 = (; zip(names, columns)...)