SHOGUN  4.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
StaticInterfaces.mainpage
Go to the documentation of this file.
1 /*! \page staticinterfaces Static Interfaces
2 
3 As mentioned before SHOGUN interfaces to several programming languages and
4 toolkits such as Matlab(tm), R, Python, Octave. The following sections shall
5 give you an overview over the static interface commands of SHOGUN. For the
6 static interfaces we tried to preserve the syntax of the commands in a
7 consistent manner through all the different languages. However as in some cases
8 this was not possible and we document the subtle differences of syntax and
9 semantic in the respective toolkit. Instead of reading through all this, we
10 suggest to have a look at the large number of examples available in the \b
11 examples / interface directory. For example examples/R or examples/python etc.
12 
13 <b>Overview of Static Interfaces & Testing the Installation</b>
14 \li \ref staticoctaveinterf_sec
15 \li \ref staticpythoninterf_sec
16 \li \ref staticrinterf_sec
17 
18 <b>Interface Commands</b>
19 \li \ref staticiffeatures_sec
20 \li \ref staticifkernel_sec
21 \li \ref staticifsvm_sec
22 \li \ref staticifhmm_sec
23 \li \ref staticifpoim_sec
24 \li \ref staticifutil_sec
25 \li \ref staticifexample_sec
26 
27 <b>Command Reference</b>
28 \li \ref staticifcmdref_sec
29 
30 \section staticifoverview_sec Overview of Static Interfaces & Testing the Installation
31 
32 \subsection staticoctaveinterf_sec Static Matlab and Octave Interface
33 
34 Since octave is nowadays up to par with matlab a single documentation for both
35 interfaces is sufficient and will be based on octave (matlab can be used
36 synonymously).
37 
38 To start SHOGUN in octave, start octave and check if it is correctly installed
39 by by typing ( let ">" be the octave prompt )
40 
41 \verbatim
42  sg('help')
43 \endverbatim
44 
45 inside of octave. This should show you some help text.
46 
47 \subsection staticpythoninterf_sec Static Python Interface
48 
49 To start SHOGUN in python, start python and check if it is correctly installed
50 by by typing ( let ">" be the python prompt )
51 
52 \verbatim
53  from sg import sg
54  sg('help')
55 \endverbatim
56 
57 inside of python. This should show you some help text.
58 
59 \subsection staticrinterf_sec Static R Interface
60 
61 To fire up SHOGUN in R make sure that you have SHOGUN correctly installed in
62 R. You can check this by typing ( let ">" be the R prompt ):
63 
64 \verbatim
65  > library()
66 \endverbatim
67 
68 inside of R, this command should list all R packages that have been
69 installed on your system.
70 You should have an entry like:
71 
72 \verbatim
73  sg The SHOGUN Machine Learning Toolbox
74 \endverbatim
75 
76 After you made sure that SHOGUN is installed correctly you can start it via:
77 
78 \verbatim
79  > library(sg)
80 \endverbatim
81 
82 you will see some informations of the SHOGUN core (compile options etc).
83 After this command R and SHOGUN are ready to receive your commands.
84 
85 In general all commands in SHOGUN are issued using the function sg(...).
86 To invoke the SHOGUN command help one types:
87 
88 \verbatim
89  > sg('help')
90 \endverbatim
91 
92 and then a help text appears giving a short description of all commands.
93 
94 
95 \section staticifcmds Static Interface Commands
96 
97 \subsection staticiffeatures_sec Features
98 These functions transfer data from the interface to shogun and back.
99 Suppose you have a matlab matrix or R matrix "features" which
100 contains your training data and you want to register this data, you simply
101 type:
102 
103 Transfer the features to shogun
104 \arg \b set_features \verbatim sg('set_features', 'TRAIN|TEST', features[, DNABINFILE|<ALPHABET>]) \endverbatim
105 \arg \b add_features \verbatim sg('add_features', 'TRAIN|TEST', features[, DNABINFILE|<ALPHABET>]) \endverbatim
106 
107 Features can be char/byte/word/int/real valued matrices, real values sparse
108 matrices, or strings (lists or cell arrays of strings). When dealing with
109 strings an alphabet name has to be specified (DNA, RAW, ...). Use 'TRAIN' to
110 tell SHOGUN that this is the data you want to train your classifier and TEST for
111 the test data.
112 
113 In contrast to \b set_features, \b add_features will create a combined feature
114 object and append the features to it. This is useful when dealing with a set of
115 different features (real valued and strings) and multiple kernels.
116 
117 In case a single string was set using \b set_features, it can be "multiplexed"
118 by sliding a window over it using
119 \arg \b from_position_list \verbatim sg('from_position_list', 'TRAIN|TEST', winsize, shift[, skip]) \endverbatim
120 or
121 \arg \b obtain_from_sliding_window \verbatim sg('obtain_from_sliding_window', winsize, skip) \endverbatim
122 
123 Deletes the features which we assigned before in the actual SHOGUN session.
124 \arg clean_features \verbatim sg('clean_features') \endverbatim
125 
126 Obtain the Features from shogun
127 \arg \b get_features \verbatim [features]=sg('get_features', 'TRAIN|TEST') \endverbatim
128 
129 One proceeds similar when assigning labels to the training data and obtaining
130 labels from shogun: The commands
131 
132 \arg \b set_labels \verbatim sg('set_labels', 'TRAIN', trainlab) \endverbatim
133 \arg \b get_labels \verbatim [labels]=sg('get_labels', 'TRAIN|TEST') \endverbatim
134 
135 tell SHOGUN that the labels of the assigned training data reside in trainlab,
136 respectively return the current labels (note that currently all data is
137 \b copied into SHOGUN, so modifications to trainlab are local within the
138 interface).
139 
140 \subsection staticifkernel_sec Kernel & Distances
141 
142 Kernel and DistanceMatrix specific commands, used to create, obtain and setting
143 the kernel matrix.
144 
145 Creating a kernel in shogun
146 \arg \b set_kernel \verbatim sg('set_kernel', 'KERNELNAME', 'FEATURETYPE', CACHESIZE, PARAMETERS) \endverbatim
147 \arg \b add_kernel \verbatim sg('add_kernel', WEIGHT, 'KERNELNAME', 'FEATURETYPE', CACHESIZE, PARAMETERS) \endverbatim
148 
149 Here KERNELNAME is the name of the kernel one wishes to use, FEATURETYPE the
150 type of features (e.g. REAL for standard realvalued feature vectors), CACHESIZE
151 the size of the kernel cache in megabytes and PARAMETERS kernel specific
152 additional parameters.
153 
154 \subsubsection staticifsuppkernels_sec Supported Kernels
155 
156 The following kernels are implemented in SHOGUN:
157 
158 \li AUC
159 \li Chi2
160 \li Spectrum
161 \li Const Kernel
162 \li User defined CustomKernel
163 \li Diagonal Kernel
164 \li Kernel from Distance
165 \li Fixed Degree StringKernel
166 \li Gaussian \f$ k(x,x')=e^{-\frac{||x-x'||^2}{\sigma}} \f$
167 
168 To work with a gaussian kernel on real values one issues:
169 \verbatim sg('set_kernel', 'GAUSSIAN', 'TYPE', CACHESIZE, SIGMA)\endverbatim
170 
171 For example:
172 \verbatim sg('set_kernel', 'GAUSSIAN', 'REAL', 40, 1)\endverbatim
173 creates a gaussian kernel on real values with a cache size of 40MB and a sigma
174 value of one. Available types for the gaussian kernel: REAL, SPARSEREAL.
175 
176 \li Gaussian Shift Kernel
177 \li Histogram Kernel
178 \li Linear \f$k(x,x')=x\cdot x'\f$
179 
180 A linear kernel is created via:
181 \verbatim sg('set_kernel', 'LINEAR', 'TYPE', CACHESIZE)\endverbatim
182 
183 For example:
184 \verbatim sg('add_kernel', 1.0, 'LINEAR', 'REAL', 50')\endverbatim
185 
186 creates a linear kernel of cache size 50 for real datavalues, with weight 1.0.
187 
188 Available types for the linear kernel: BYTE, WORD CHAR, REAL, SPARSEREAL.
189 
190 \li Local Alignment StringKernel
191 \li Locality Improved StringKernel
192 \li Polynomial Kernel \f$k(x,x')=(x\cdot x')^d\f$
193 
194 A polynomial kernel is created via:
195 \verbatim sg('set_kernel', 'POLY', 'TYPE', CACHESIZE, DEGREE, INHOMOGENE, NORMALIZE) \endverbatim
196 
197 For example:
198 \verbatim sg('add_kernel', 0.1, 'POLY', 'REAL', 50, 3, 0) \endverbatim
199 adds a polynomial kernel. Available types for the polynomial kernel: REAL,
200 CHAR, SPARSEREAL.
201 
202 \li Salzberg Kernel
203 \li Sigmoid Kernel
204 To work with a sigmoid kernel on real values one issues:
205 
206 \verbatim sg('set_kernel', 'SIGMOID', 'TYPE', CACHESIZE, GAMMA, COEFF)\endverbatim
207 
208 For example:
209 
210 \verbatim sg('set_kernel', 'SIGMOID', 'REAL', 40, 0.1, 0.1) \endverbatim
211 
212 creates a sigmoid kernel on real values with a cache size of 40MB, a gamma
213 value of 0.1 and a coefficient of 0.1. Available types for the gaussian kernel: REAL.
214 
215 \li Weighted Spectrum Kernel
216 \li Weighted Degree Kernels
217 \li Match Kernel
218 \li Custom Kernel
219 
220 Assign a user defined custom kernel, fo which only the upper triangle may be
221 given (DIAG) or the FULL matrix (FULL), or the full matrix which is then
222 internally stored as a upper triangle (FULL2DIAG).
223 \arg \b set_custom_kernel \verbatim sg('set_custom_kernel', kernelmatrix, 'DIAG|FULL|FULL2DIAG') \endverbatim
224 
225 The purpose of the get_kernel_matrix and get_distance_matrix commands is to
226 return a kernel or distance matrix representing the kernel/distance matrix for
227 the actual problem.
228 
229 \arg \b get_distance_matrix \verbatim [D]=sg('get_distance_matrix', 'TRAIN|TEST') \endverbatim
230 \arg \b get_kernel_matrix \verbatim [K]=sg('get_kernel_matrix', 'TRAIN|TEST') \endverbatim
231 
232 km refers to a matrix object.
233 
234 \subsection staticifsvm_sec SVM
235 \arg new_classifier Creates a new classifier (e.g. SVM instance).
236 \arg train_classifier Starts the training of the SVM on the assigned features and kernels.
237 
238 The get_svm command returns some properties of an SVM such as the Langrange
239 multipliers alpha, the bias b and the index of the support vectors SV (zero
240 based).
241 \arg \b get_classifier \verbatim [bias, alphas]=sg('get_svm') \endverbatim
242 \arg \b set_classifier \verbatim sg('set_classifier', bias, alphas) \endverbatim
243 
244 This commands returns a list of arguments. \b set_classifier may be later on used (after creating an SVM classifier) to set alphas and bias again.
245 
246 The result of the classification of the test sample is obtained via:
247 \arg \b classify \verbatim [result]=sg('classify') \endverbatim
248 \arg \b classify_example \verbatim [result]=sg('classify_example', feature_vector_index) \endverbatim
249 where result is a vector containing the classification result for each
250 datapoint and \b classify_example only obtains the output for a single example
251 (index is zero based like in python. note that octave, matlab, R are 1 based).
252 
253 \subsection staticifhmm_sec HMM
254 \li get_hmm
255 \li set_hmm
256 \li hmm_classify
257 \li hmm_classify_example
258 \li hmm_likelihood
259 \li get_viterbi_path
260 
261 \subsection staticifpoim_sec POIM
262 \li compute_poim_wd
263 \li get_SPEC_consensus
264 \li get_SPEC_scoring
265 \li get_WD_consensus
266 \li get_WD_scoring
267 
268 \subsection staticifutil_sec Utility
269 Miscellaneous functions.
270 
271 Returns the svn version number
272 \arg \b help \verbatim sg('get_version') \endverbatim
273 
274 Gives you a help text.
275 \arg \b help \verbatim sg('help') \endverbatim
276 \arg \b help \verbatim sg('help', 'CMD') \endverbatim
277 
278 Sets a debugging log level - useful to trace errors.
279 \arg loglevel \verbatim sg('loglevel', 'LEVEL') \endverbatim
280 LEVEL can be one of DEBUG, WARN, ERROR
281  \li ALL: very verbose logging output (useful only for hunting memory leaks)
282  \li DEBUG: verbose logging output (useful for debugging).
283  \li WARN: less logging output (useful for error search).
284  \li ERROR: only logging output on critical errors.
285 
286 For example
287 \verbatim
288  > sg('loglevel', 'ALL')
289 \endverbatim
290 gives you a list of instructions.
291 
292 
293 Let's get started, equipped with the above information on the basic SHOGUN
294 commands you are now able to create your own SHOGUN applications.
295 
296 \section staticifexample_sec Example
297 Let us discuss an example:
298 
299  \li \verbatim sg('set_features', 'TRAIN', traindat) \endverbatim
300  registers the training sample which reside in traindat.
301 
302  \li \verbatim sg('set_labels', 'TRAIN', trainlab) \endverbatim
303  registers the training labels.
304 
305  \li \verbatim sg('set_kernel', 'GAUSSIAN', 'REAL', 100, 1.0) \endverbatim
306  creates a new gaussian kernel for reals with cache size 100Mb and width = 1.
307 
308  \li \verbatim sg('new_classifier', 'SVMLIGHT') \endverbatim
309  creates a new SVM object inside the SHOGUN core.
310 
311  \li \verbatim sg('c', 20.0) \endverbatim
312  sets the C value of the new SVM to 20.0.
313 
314  \li \verbatim sg('train_classifier') \endverbatim
315  attaches the data to the kernel and does some initialization then
316  starts the training on the sample.
317 
318  \li \verbatim sg('set_features', 'TEST', testdat) \endverbatim
319  registers the test sample
320 
321  \li \verbatim out=sg('classify') \endverbatim
322  attaches the data to the kernel and classifies. Then
323  gives you the classification result as a vector.
324 
325 
326 \section staticifcmdref_sec Function Reference
327  \li \subpage staticoctave
328  \li \subpage staticpython
329  \li \subpage staticcmdline
330  \li \subpage staticr
331 */

SHOGUN Machine Learning Toolbox - Documentation