forked from probml/pmtk3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
binaryFA code now works in unsupervised setting
git-svn-id: https://pmtk3.googlecode.com/svn/trunk@2769 b6abd7f4-f95b-11de-aa3c-59de0406b4f5
- Loading branch information
1 parent
c98489c
commit 5c68983
Showing
10 changed files
with
212 additions
and
241 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,37 +1,55 @@ | ||
% Demo of factor analysis applied to some synthetic binary data | ||
% Demo of factor analysis applied to some synthetic 2d binary data | ||
|
||
% This file is from pmtk3.googlecode.com | ||
|
||
%function [W, b, proto] = tippingDemo(); | ||
|
||
p = 16; | ||
setSeed(0); | ||
D = 16; | ||
K = 3; | ||
proto = rand(p,K) < 0.5; | ||
data = []; | ||
dataClean = []; | ||
proto = rand(D,K) < 0.5; | ||
M = 50; | ||
source = [1*ones(1,M) 2*ones(1,M) 3*ones(1,M)]; | ||
for k=1:K | ||
tmp = repmat(proto(:,k), 1, M); | ||
dataClean = [dataClean tmp]; | ||
noise = rand(p, M) < 0.05; | ||
tmp(noise) = 1-tmp(noise); | ||
data = [data tmp]; | ||
N = numel(source); | ||
dataClean = zeros(N, D); | ||
for n=1:N | ||
src = source(n); | ||
dataClean(n, :) = proto(:, src)'; | ||
end | ||
noiseLevel = 0.05; | ||
flipMask = rand(N,D) < noiseLevel; | ||
dataNoisy = dataClean; | ||
dataNoisy(flipMask) = 1-dataClean(flipMask); | ||
dataMissing = dataClean; | ||
dataMissing(flipMask) = nan; | ||
|
||
figure; imagesc(dataNoisy); colormap(gray); | ||
title('noisy binary data') | ||
printPmtkFigure('binaryPCAinput'); | ||
|
||
figure; imagesc(data'); colormap(gray);printPmtkFigure('binaryPCAinput'); | ||
figure; imagesc(dataClean'); colormap(gray) | ||
figure; imagesc(dataClean); colormap(gray); title('hidden truth') | ||
|
||
q = 2; | ||
%[W, b, muPost] = binaryPcaFitVarEm(data, 2); | ||
model = binaryFAfit(data, 2); | ||
muPost = binaryFAinferLatent(model, data); | ||
% Fit model | ||
[model, loglikHist] = binaryFAfit(dataNoisy, 2, 'maxIter', 10, 'verbose', true); | ||
figure; plot(loglikHist); title('(lower bound on) loglik vs iter for EM') | ||
|
||
% Latent 2d embedding | ||
muPost = binaryFAinferLatent(model, dataNoisy); | ||
figure; | ||
symbols = {'ro', 'gs', 'k*'}; | ||
for k=1:K | ||
ndx = (source==k); | ||
plot(muPost(1,ndx), muPost(2,ndx), symbols{k}); | ||
hold on | ||
end | ||
title('latent embedding') | ||
printPmtkFigure('binaryPCAoutput') | ||
|
||
% Denoising | ||
[postPred] = binaryFApredictMissing(model, dataNoisy); | ||
yhat = postPred > 0.5; | ||
figure; imagesc(yhat); colormap(gray); title('prediciton given noisy') | ||
|
||
% Imputation | ||
[postPred] = binaryFApredictMissing(model, dataMissing); | ||
yhat = postPred > 0.5; | ||
figure; imagesc(yhat); colormap(gray); title('prediction given missing data') |
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
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
Oops, something went wrong.