Skip to content

Commit f44268e

Browse files
committed
Add reapply for EigenAnalysis
1 parent 454df8f commit f44268e

File tree

1 file changed

+30
-2
lines changed

1 file changed

+30
-2
lines changed

src/transforms/eigenanalysis.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function apply(transform::EigenAnalysis, table)
6464
𝒯 = (; zip(names, eachcol(Z))...)
6565
newtable = 𝒯 |> Tables.materializer(table)
6666

67-
newtable, (μ, S⁻¹)
67+
newtable, (μ, S, S⁻¹)
6868
end
6969

7070
function revert(::EigenAnalysis, newtable, cache)
@@ -75,7 +75,7 @@ function revert(::EigenAnalysis, newtable, cache)
7575
Z = Tables.matrix(newtable)
7676

7777
# retrieve cache
78-
μ, S⁻¹ = cache
78+
μ, S, S⁻¹ = cache
7979

8080
# undo projection
8181
Y = Z * S⁻¹
@@ -88,6 +88,34 @@ function revert(::EigenAnalysis, newtable, cache)
8888
𝒯 |> Tables.materializer(newtable)
8989
end
9090

91+
function reapply(transform::EigenAnalysis, table, cache)
92+
# basic checks
93+
for assertion in assertions(transform)
94+
assertion(table)
95+
end
96+
97+
# original columns names
98+
names = Tables.columnnames(table)
99+
100+
# table as matrix
101+
X = Tables.matrix(table)
102+
103+
# retrieve cache
104+
μ, S, S⁻¹ = cache
105+
106+
# center the data
107+
Y = X .- μ
108+
109+
# project the data
110+
Z = Y * S
111+
112+
# table with transformed columns
113+
𝒯 = (; zip(names, eachcol(Z))...)
114+
newtable = 𝒯 |> Tables.materializer(table)
115+
116+
newtable, cache
117+
end
118+
91119
function eigenmatrices(transform, Y)
92120
proj = transform.proj
93121

0 commit comments

Comments
 (0)