-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
310369a
commit 16d3110
Showing
12 changed files
with
193 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using ExpFamilyPCA | ||
|
||
|
||
n_samples = 5 | ||
n_dims = 10 | ||
X = rand(0:1, n_samples, n_dims) # generate random binary data | ||
|
||
n_components = 2 | ||
epca = BernoulliPCA(n_components, n_dims) | ||
fit!(epca, X; verbose=true, maxiter=10) | ||
|
||
X̃ = compress(epca, X) | ||
X_recon = decompress(epca, X̃) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 13, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loss: 346.57359027997245\n", | ||
"Loss: " | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"339.4651260162266\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loss: 326.83851096508596\n", | ||
"Loss: " | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"313.16798822607956\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loss: 300.47024994515317\n", | ||
"Loss: " | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"287.68813149707574\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loss: 278.5198879020468\n", | ||
"Loss: " | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"272.07194894059666\n" | ||
] | ||
}, | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Loss: 267.2032539001495\n", | ||
"Loss: " | ||
] | ||
} | ||
], | ||
"source": [ | ||
"using ExpFamilyPCA\n", | ||
"\n", | ||
"n_samples = 10\n", | ||
"n_dims = 5\n", | ||
"X = rand(0:1, n_samples, n_dims) # generate random binary data\n", | ||
"\n", | ||
"n_components = 2\n", | ||
"epca = BernoulliPCA(n_components, n_dims)\n", | ||
"fit!(epca, X; verbose=true, maxiter=10)\n", | ||
"\n", | ||
"X̃1 = compress(epca, X)\n", | ||
"recon1 = decompress(epca, X̃1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"using MultivariateStats\n", | ||
"\n", | ||
"M = fit(PCA, X; maxoutdim=n_components)\n", | ||
"X̃2 = predict(M, X)\n", | ||
"recon2 = reconstruct(M, X̃2)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"using LinearAlgebra\n", | ||
"\n", | ||
"dist1 = X .- recon1\n", | ||
"dist2 = X .- recon2\n", | ||
"\n", | ||
"# From theory, we expect the EPCA reconstruction to do better on the L1 norm but worse on L2\n", | ||
"println(\"EPCA L1:\", norm(dist1, 1))\n", | ||
"println(\"PCA L1:\", norm(dist2, 1))\n", | ||
"println()\n", | ||
"println(\"EPCA L2:\", norm(dist1, 2))\n", | ||
"println(\"PCA L2:\", norm(dist2, 2))" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Julia 1.10.1", | ||
"language": "julia", | ||
"name": "julia-1.10" | ||
}, | ||
"language_info": { | ||
"file_extension": ".jl", | ||
"mimetype": "application/julia", | ||
"name": "julia", | ||
"version": "1.10.1" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@testset "PoissonPCA" begin | ||
analytic_test(PoissonPCA, 500, 200) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,24 @@ | ||
using ExpFamilyPCA | ||
using Test | ||
|
||
using Symbolics | ||
using Random | ||
Random.seed!(1) | ||
|
||
|
||
function analytic_test(epca_constructor::Function, l::Integer, n::Integer, d::Integer) | ||
X = rand(n, d) | ||
epca = epca_constructor(l, d) | ||
fit!(epca, X, maxiter=50) | ||
X̃ = compress(X) | ||
X_recon = decompress(X̃) | ||
@test X ≈ X_recon | ||
end | ||
|
||
|
||
# TODO add numeric tests | ||
|
||
|
||
@testset "ExpFamilyPCA.jl" begin | ||
# Write your tests here. | ||
include("poisson_tests.jl") | ||
end |
Empty file.
Empty file.