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.
git-svn-id: https://pmtk3.googlecode.com/svn/trunk@2791 b6abd7f4-f95b…
…-11de-aa3c-59de0406b4f5
- Loading branch information
1 parent
a9df674
commit 48a2c07
Showing
25 changed files
with
252 additions
and
140 deletions.
There are no files selected for viewing
Binary file not shown.
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,17 +1,4 @@ | ||
% This file stores hard coded paths and configuration variables | ||
% Use getConfigValue(varname) to access a value, e.g. | ||
% getConfigValue('PMTKsupportLink') | ||
% | ||
% If a config-local.txt file is found, its values will override these. | ||
% | ||
% PMTKmetaDirs meta, docs, tmp | ||
% PMTKred #990000 | ||
% PMTKauthors Kevin Murphy, Matt Dunham | ||
% PMTKcodeDirs toolbox, demos, localUtil, matlabTools | ||
% PMTKgvizPath C:\Program Files\Graphviz2.26\bin | ||
% PMTKlocalWikiPath C:\path\to\pmtk3Wiki | ||
% PMTKlocalDataPath /Users/kpmurphy/GoogleCode/pmtkdata | ||
% PMTKlocalSupportPath /Users/kpmurphy/GoogleCode/pmtksupport | ||
% PMTKpmlBookSource /Users/kpmurphy/Dropbox/MLbook/Text | ||
% PMTKpmlFigures /Users/kpmurphy/Dropbox/MLbook/Figures | ||
% PMTKlightSpeedDir lightspeed2.3 | ||
% PMTKgvizPath C:\Program Files\Graphviz2.26\bin | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
function catFAdemo() | ||
% Factor analysis with categorical and continuous data | ||
% We reproduce the demo from | ||
% http://www.cs.ubc.ca/~emtiyaz/software/mixedDataFA.html | ||
% This just check the code runs, it is not intrinsically interesting. | ||
|
||
clear all | ||
setSeed(16) | ||
% generate data - data is stored along columns not rows! | ||
[trainData,testData,simParams] = makeSimDataMixedDataFA(100); | ||
nClass = simParams.nClass; | ||
% introduce missing variables in train data | ||
missProb = 0.1; | ||
trainData.continuousTruth = trainData.continuous; | ||
trainData.discreteTruth = trainData.discrete; | ||
[D,N] = size(trainData.continuous); | ||
miss = rand(D,N)<missProb; | ||
trainData.continuous(miss) = NaN; | ||
[D,N] = size(trainData.discrete); | ||
miss = rand(D,N)<missProb; | ||
trainData.discrete(miss) = NaN; | ||
|
||
|
||
Dz = 2; | ||
[model, loglikTrace] = catFAfit(trainData.discrete', trainData.continuous', Dz); | ||
|
||
[mu, Sigma, loglik] = catFAinferLatent(model, testData.discrete', testData.continuous') | ||
|
||
[predD, predC] = catFApredictMissing(model,testData.discrete', testData.continuous') | ||
|
||
|
||
end | ||
|
||
function [trainData, testData, params] = makeSimDataMixedDataFA(N) | ||
% [TRAINDATA, TESTDATA, PARAMS] = makeSimDataMixedDataFA(N) makes simulated data | ||
% for mixedDataFA with N data points | ||
% | ||
% Written by Emtiyaz, CS, UBC | ||
% Modified on June 09, 2010 | ||
|
||
missProb = 0.3; | ||
Dz = 2; | ||
mean_ = [5 -5]';% -5 -5]'; | ||
covMat = eye(Dz); | ||
z = repmat(mean_,1,N) + chol(covMat)*randn(Dz,N); | ||
Dc = 5; | ||
nClass = 2*ones(10,1);%[3 2 4]; | ||
noiseCovMat = 0.01*eye(Dc);%abs(diag(randn(Dc,1))); | ||
Bc = rand(Dc,Dz); | ||
|
||
% generate data | ||
yc = Bc*z + chol(noiseCovMat)*randn(Dc,N); | ||
%yc = yc - repmat(mean(yc,2), 1, N); | ||
|
||
Bm = []; | ||
for c = 1:length(nClass) | ||
Bmc = rand(nClass(c)-1,Dz); | ||
p = [exp(Bmc*z); ones(1,N)]; | ||
pMult = p./repmat(sum(p,1),nClass(c),1); | ||
yd(c,:) = sum(repmat([1:nClass(c)],N,1).*mnrnd(1,pMult'),2); | ||
Bm = [Bm; Bmc]; | ||
end | ||
|
||
% model parameters structure | ||
params.nClass = nClass; | ||
params.mean = mean_; | ||
params.covMat = covMat; | ||
params.noiseCovMat = noiseCovMat; | ||
params.betaMult = Bm; | ||
params.betaCont = Bc; | ||
|
||
% split test and train data | ||
ratio = .7; | ||
[trainData, testData] = splitData(yc,yd,ratio); | ||
|
||
%{ | ||
% introduce missing variables in test data | ||
testData.continuousTruth = testData.continuous; | ||
testData.discreteTruth = testData.discrete; | ||
[D,N] = size(testData.continuous); | ||
miss = rand(D,N)<missProb; | ||
testData.continuous(miss) = NaN; | ||
[D,N] = size(testData.discrete); | ||
miss = rand(D,N)<missProb; | ||
testData.discrete(miss) = NaN; | ||
%} | ||
|
||
|
||
end | ||
|
||
function [trainData, testData, idx] = splitData(yc, yd, ratio) | ||
% splits data into training and testing set | ||
% yc is the continuous data, yd is discrete data | ||
% ratio is the split ratio | ||
|
||
[Dc,Nc] = size(yc); | ||
[Dd,Nd] = size(yd); | ||
N = max(Nc,Nd); | ||
nTrain = ceil(ratio*N); | ||
idx = randperm(N); | ||
if Dc>0 | ||
testData.continuous = yc(:,idx(nTrain+1:end)); | ||
trainData.continuous = yc(:,idx(1:nTrain)); | ||
else | ||
testData.continuous = []; | ||
trainData.continuous = []; | ||
end | ||
if Dd>0 | ||
testData.discrete = yd(:,idx(nTrain+1:end)); | ||
trainData.discrete = yd(:,idx(1:nTrain)); | ||
else | ||
testData.discrete = []; | ||
trainData.discrete = []; | ||
end | ||
|
||
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
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
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
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.