Skip to content

Commit

Permalink
move pca to an extension (#52)
Browse files Browse the repository at this point in the history
* move pca to an extension

* add documentation for dummy pca method
  • Loading branch information
gdkrmr authored Sep 28, 2023
1 parent 2c08ec7 commit fdc8b02
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
9 changes: 8 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,17 @@ OnlineStatsBase = "1"
StatsBase = "0.32.1, 0.33, 0.34"
julia = "1"

[extensions]
PcaExt = "MultivariateStats"

[extras]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random", "StatsBase"]
test = ["Test", "Random", "StatsBase", "MultivariateStats"]

[weakdeps]
MultivariateStats = "6f286f6a-111f-5878-ab1e-185364afe411"
10 changes: 8 additions & 2 deletions src/pca.jl → ext/PcaExt.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module PcaExt

using WeightedOnlineStats

import StatsBase
import StatsBase: ZScoreTransform
export ZScoreTransform
Expand All @@ -9,7 +13,7 @@ import MultivariateStats:
predict

export
pca, PCA, pcacov, indim, outdim, projection, principalvar, principalvars,
PCA, pcacov, indim, outdim, projection, principalvar, principalvars,
tprincipalvar, tresidualvar, tvar, principalratio, transform, reconstruct

"""
Expand All @@ -29,7 +33,7 @@ from a `WeightedCovMatrix`.
c = fit!(WeightedCovMatrix(), rand(4, 100), rand(100))
t, p = pca(c)
"""
function pca(
function WeightedOnlineStats.pca(
x::WeightedCovMatrix{T};
cov_pca::Bool = false,
maxoutdim::Int = size(x, 1),
Expand Down Expand Up @@ -85,3 +89,5 @@ end
# return x
# end


end # module
11 changes: 10 additions & 1 deletion src/WeightedOnlineStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,16 @@ include("sum.jl")
include("mean.jl")
include("var.jl")
include("covmatrix.jl")
include("pca.jl")

export pca
"""
`pca` creates a PCA object from a `WeightedCovMatrix` object. Requires MultivariateStats to be loaded!
"""
function pca end
if !isdefined(Base, :get_extension)
include("../ext/PcaExt.jl")
end

include("histogram.jl")

end # module WeightedOnlineStats

0 comments on commit fdc8b02

Please sign in to comment.