-
Notifications
You must be signed in to change notification settings - Fork 795
/
initPmtk3.m
191 lines (163 loc) · 5.73 KB
/
initPmtk3.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
%% Run this script to initialize PMTK3
% This file is from pmtk3.googlecode.com
set(0,'DefaultAxesFontSize',15,'DefaultTextFontSize',15);
format compact
more off; % especially important in Octave - init may fail without it
verbose = true;
if verbose
disp('initializing pmtk3');
end
isMatlab = ~isempty(ver('matlab'));
if ~isMatlab
error('run initPmtk3Octave instead')
end
%% change to the directory storing this function, (should be PMTK3 root).
w = which(mfilename());
thisDir = fileparts(w);
cd(thisDir);
addpath(thisDir);
%% include directories
%include = @(d, varargin)addpath(genpathPMTK(d, isMatlab), varargin{:});
include = @(d)addpath(genpathPMTK(d));
include(fullfile(thisDir, 'projects'));
include(fullfile(thisDir, 'pmtkTools'));
include(fullfile(thisDir, 'matlabTools'));
include(fullfile(thisDir, 'toolbox'));
include(fullfile(thisDir, 'demos'));
include(fullfile(thisDir, 'data'));
include(fullfile(thisDir, 'bigData'));
%include(fullfile(thisDir, 'pmtkdataSmall'));
%include(fullfile(thisDir, 'pmtkdataCopy')); % may be initially empty
include(fullfile(thisDir, 'pmtksupportCopy')); % may be initially empty
if exist(fullfile(thisDir, 'docs', 'tutorial'), 'dir')
include(fullfile(thisDir, 'docs', 'tutorial'));
end
%% include PMTK support
source = getConfigValue('PMTKlocalSupportPath');
if exist(source, 'dir')
include(source);
fprintf('adding %s to path\n', source);
end
if ~(exist('pmtkSupportRoot', 'file') == 2)
downloadAllSupport(fullfile(pmtk3Root(), 'pmtksupportCopy'), false);
end
%% include graphViz
if ~verLessThan('matlab', '7.6.0')
gvizDir = getConfigValue('PMTKgvizPath');
if exist(gvizDir, 'dir')
addtosystempath(gvizDir);
fprintf('adding %s to path\n', gvizDir);
end
end
%% add various binary executables to the system path.
if exist('pmtkSupportRoot', 'file')
folder = pmtkSupportRoot();
dirs = {'svmLightWindows' , ...
'liblinear-1.51\windows' , ...
'libsvm-mat-2.9.1', ...
'mplp-1.0'};
for i=1:length(dirs)
addtosystempath(fullfile(folder, dirs{i}))
end
end
%% add local data directory to path if it exists
source = getConfigValue('PMTKlocalDataPath');
if exist(source, 'dir')
include(source);
fprintf('adding %s to path\n', source);
end
%% Generate some function files concerning user's setup
pmtkInfoDir = fullfile(thisDir, 'pmtkTools', 'systemInfo');
% write isOctave.m
text = { 'function answer = isOctave()'
'%autogenerated by initPmtk3()'
sprintf('answer = %d;', ~isMatlab);
'end'
};
writeText(text, fullfile(pmtkInfoDir, 'isOctave.m'));
% write libdaiInstalled.m
installed = (exist('dai', 'file') == 3);
text = { 'function answer = libdaiInstalled()'
'%autogenerated by initPmtk3()'
sprintf('answer = %d;', installed);
'end'
};
writeText(text, fullfile(pmtkInfoDir, 'libdaiInstalled.m'));
% write UGMInstalled.m
installed = (exist('UGM_makeNodePotentialsC', 'file') == 3);
text = { 'function answer = UGMInstalled()'
'%autogenerated by initPmtk3()'
sprintf('answer = %d;', installed);
'end'
};
writeText(text, fullfile(pmtkInfoDir, 'UGMInstalled.m'));
% write glmnetInstalled.m
% Even if the binary file exists, it may fail to run
% e.g. on MAC OS X, the .mexmaci64 file exists by the fortran library
% /usr/local/lib/libgfortran.2.dylib is missing
installed = true;
try
x=randn(100,20); y=randn(100,1); fit=glmnet(x,y);
catch
installed = false;
end
text = { 'function answer = glmnetInstalled()'
'%autogenerated by initPmtk3()'
sprintf('answer = %d;', installed);
'end'
};
writeText(text, fullfile(pmtkInfoDir, 'glmnetInstalled.m'));
% write svmInstalled.m
% The binary file might not exist for some OS eg., libsvm has no mexmaci64
% svmFit could call somethign else instead
installed = true;
try
x=randn(10,20); y=randn(10,1);
model = svmFit(x, y, 'C', 1,'kernelParam', 1, 'kernel', 'rbf');
catch
installed = false;
end
text = { 'function answer = svmInstalled()'
'%autogenerated by initPmtk3()'
sprintf('answer = %d;', installed);
'end'
};
writeText(text, fullfile(pmtkInfoDir, 'svmInstalled.m'));
% write is*ToolboxInstalled.m functions
toolbox = {'stats', 'bioinfo', 'optim', 'signal', 'images', 'symbolic',...
'nnet', 'splines'};
for t=1:numel(toolbox)
if isMatlab
installed = ...
onMatlabPath(fullfile(matlabroot, 'toolbox', toolbox{t}), true);
else
installed = false;
end
fname = sprintf('%sToolboxInstalled', toolbox{t});
text = { sprintf('function answer = %s()', fname)
'% autogenerated by initPmtk3()'
sprintf('answer = %d;', installed)
'end'
};
writeText(text, fullfile(pmtkInfoDir, [fname, '.m']));
end
%% compile mex
if false % automated compilation does not work on all systems since the
% Matlab versions for these OSs do not come with a built in
% compiler, e.g. 64bit windows.
% We use the existence of the 'mexDone.txt' as a marker so that we only
% check for uncompiled mex files the first time this is run.
if isMatlab
alreadyIncluded = {'mexw32', 'mexglx'}; % compiled files are already included for these types
checkFile = fullfile(pmtk3Root(), 'localUtil', 'mexDone.txt');
if ~ismember(mexext(), alreadyIncluded) && ~exist(checkFile, 'file')
installLightspeedPMTK();
compileC(pmtk3Root()); % does not compile external packages, most of which require special linkage
writeText({'Autogenerated by initPmtk3'}, checkFile);
end
end
end
%%
if verbose,
disp('welcome to pmtk3');
end