Skip to content

Commit

Permalink
checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingWorkshop committed May 4, 2024
1 parent 823ee9c commit d4efac6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
20 changes: 11 additions & 9 deletions src/explicit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function PoissonEPCA()
# assumes X = {integers}
epsilon = eps()
@. begin
Bregman(p, q) = p * log((p + epsilon) / (q + epsilon)) + q - p
Bregman(p, q) = p * (log(p + epsilon) - log(q + epsilon)) + q - p
g(theta) = exp(theta)
end
mu = g(0)
Expand All @@ -25,7 +25,7 @@ function BernoulliEPCA()
# assumes X = {0, 1}
epsilon = eps()
@. begin
Bregman(p, q) = p * log((p + epsilon)/ (q + epsilon)) + (1 - p) * log((1 - p + epsilon) / (1 - q + epsilon))
Bregman(p, q) = p * (log(p + epsilon) - log(q + epsilon)) + (1 - p) * (log(1 - p + epsilon) - log(1 - q + epsilon))
g(theta) = exp(theta) / (1 + exp(theta))
end
mu = g(1)
Expand Down Expand Up @@ -57,7 +57,7 @@ function fit!(
)
B, g = epca.Bregman, epca.g
L(theta) = begin
X_hat= g.(theta)
X_hat = g.(theta)
sum(B(X, X_hat) + epsilon * B(mu, X_hat))
end
n, d = size(X)
Expand All @@ -66,9 +66,9 @@ function fit!(
for i in 1:maxiter
V = Optim.minimizer(optimize(V_hat->L(A * V_hat), V))
result = optimize(A_hat->L(A_hat * V), A)
loss = Optim.minimum(result)
A = Optim.minimizer(result)
if verbose && (i % print_steps == 0 || i == 1)
loss = Optim.minimum(result)
println("Iteration: $i/$maxiter | Loss: $loss")
end
end
Expand All @@ -81,22 +81,24 @@ function compress(
epca::ExplicitEPCA,
X;
mu=epca.mu,
maxoutdim=1,
maxiter=100,
verbose=false,
print_stesp=10,
print_steps=10,
epsilon=eps()
)
B, g, V = epca.Bregman, epca.g, epca.V
L(theta) = begin
X_hat= g.(theta)
X_hat = g.(theta)
sum(@. B(X, X_hat) + epsilon * B(mu, X_hat))
end
n, _ = size(X)
A = ones(n, maxoutdim)
outdim = size(V)[1]
A = ones(n, outdim)
for _ in 1:maxiter
A = Optim.minimizer(optimize(A_hat->L(A_hat * V), A))
result = optimize(A_hat->L(A_hat * V), A)
A = Optim.minimizer(result)
if verbose && (i % print_steps == 0 || i == 1)
loss = Optim.minimum(result)
println("Iteration: $i/$maxiter | Loss: $loss")
end
end
Expand Down
13 changes: 8 additions & 5 deletions src/implicit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ function fit!(
for i in 1:maxiter
V = Optim.minimizer(optimize(V_hat->L(A * V_hat), V))
result = optimize(A_hat->L(A_hat * V), A)
loss = Optim.minimum(result)
A = Optim.minimizer(result)
if verbose && (i % print_steps == 0 || i == 1)
loss = Optim.minimum(result)
println("Iteration: $i/$maxiter | Loss: $loss")
end
end
Expand All @@ -96,8 +96,8 @@ end

function compress(
epca::ImplicitEPCA,
X,
mu;
X;
mu=1, # NOTE: mu = 1 may not be valid for all link functions.
maxiter=100,
verbose=false,
print_steps=10,
Expand All @@ -106,11 +106,14 @@ function compress(
)
L = _make_loss(epca, X, mu, epsilon; tol=tol)
n, _ = size(X)
A = ones(n, maxoutdim)
V = epca.V
outdim = size(V)[1]
A = ones(n, outdim)
for i in 1:maxiter
A = Optim.minimizer(optimize(A_hat->L(A_hat * V), A))
result = optimize(A_hat->L(A_hat * V), A)
A = Optim.minimizer(result)
if verbose && (i % print_steps == 0 || i == 1)
loss = Optim.minimum(result)
println("Iteration: $i/$maxiter | Loss: $loss")
end
end
Expand Down
Empty file added src/utils.jl
Empty file.

0 comments on commit d4efac6

Please sign in to comment.