SHOGUN  3.2.1
Examples for Static Command Line Interface

To run the examples issue

shogun name_of_example.sg


# Classifier

• examples/documented/cmdline_static/classifier_gmnpsvm.sg
% In this example a multi-class support vector machine is trained on a toy data
% set and the trained classifier is used to predict labels of test examples.
% The training algorithm is based on BSVM formulation (L2-soft margin
% and the bias added to the objective function) which is solved by the Improved
% Mitchell-Demyanov-Malozemov algorithm. The training algorithm uses the Gaussian
% kernel of width 2.1 and the regularization constant C=1.2. The bias term of the
% classification rule is not used. The solver stops if the relative duality gap
% falls below 1e-5 and it uses 10MB for kernel cache.
%
% For more details on the used SVM solver see
%  V.Franc: Optimization Algorithms for Kernel Methods. Research report.
%  CTU-CMP-2005-22. CTU FEL Prague. 2005.
%  ftp://cmp.felk.cvut.cz/pub/cmp/articles/franc/Franc-PhD.pdf .
%

% GMNPSVM
print GMNPSVM

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_multiclass.dat
new_classifier GMNPSVM
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_gpbtsvm.sg
% In this example a two-class support vector machine classifier is trained on a
% toy data set and the trained classifier is used to predict labels of test
% examples. As training algorithm Gradient Projection Decomposition Technique
% (GPDT) is used with SVM regularization parameter C=1.2 and a Gaussian
% kernel of width 2.1 and 10MB of kernel cache.
%
% For more details on GPDT solver see http://dm.unife.it/gpdt
%
%

% GPBTSVM
print GPBTSVM

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier GPBTSVM
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_knn.sg
% This example shows usage of a k-nearest neighbor (KNN) classification rule on
% a toy data set. The number of the nearest neighbors is set to k=3 and the distances
% are measured by the Euclidean metric. Finally, the KNN rule is applied to predict
% labels of test examples.

% KNN
print KNN

set_distance EUCLIDEAN REAL
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier KNN

train_classifier 3

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_lda.sg
% In this example a linear two-class classifier is trained based on the Linear
% Discriminant Analysis (LDA) from a toy 2-dimensional examples. The trained
% LDA classifier is used to predict test examples. Note that the LDA classifier
% is optimal under the assumption that both classes are Gaussian distributed with equal
% co-variance. For more details on the LDA see e.g.
%              http://en.wikipedia.org/wiki/Linear_discriminant_analysis
%

% LDA
print LDA

set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier LDA

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_liblinear.sg
% In this example a two-class linear support vector machine classifier is trained
% on a toy data set and the trained classifier is used to predict labels of
% test examples. As training algorithm the LIBLINEAR solver is used with the SVM
% regularization parameter C=1 and the bias term in the classification rule
% switched off. The solver iterates until it reaches epsilon-precise
% (epsilon=1.e-5) solution or the maximal training time (max_train_time=60
% seconds) is exceeded.
%
% For more details on LIBLINEAR see
%     http://www.csie.ntu.edu.tw/~cjlin/liblinear/

% LibLinear
print LibLinear

% type can be one of LIBLINEAR_L2R_LR, LIBLINEAR_L2R_L2LOSS_SVC_DUAL,
%            LIBLINEAR_L2R_L2LOSS_SVC, LIBLINEAR_L2R_L1LOSS_SVC_DUAL
new_classifier LIBLINEAR_L2R_LR
set_features TRAIN ../data/fm_train_sparsereal.dat
set_labels TRAIN ../data/label_train_twoclass.dat
svm_epsilon 1e-5
svm_use_bias 0
c 0.42

train_classifier

set_features TEST ../data/fm_test_sparsereal.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_libsvm.sg
% In this example a two-class support vector machine classifier is trained on a
% toy data set and the trained classifier is used to predict labels of test
% examples. As training algorithm LIBSVM is used with SVM regularization
% parameter C=1 and a Gaussian kernel of width 1.2 and 10MB of kernel cache and
% the precision parameter epsilon=1e-5.
%
% For more details on LIBSVM solver see http://www.csie.ntu.edu.tw/~cjlin/libsvm/

% LibSVM
print LibSVM

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier LIBSVM
c 1

train_classifier
save_classifier libsvm.model

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt
! rm libsvm.model

• examples/documented/cmdline_static/classifier_libsvmmulticlass.sg
% In this example a multi-class support vector machine classifier is trained on a
% toy data set and the trained classifier is used to predict labels of test
% examples. As training algorithm LIBSVM is used with SVM regularization
% parameter C=1.2 and the bias in the classification rule switched off and
% a Gaussian kernel of width 2.1 and 10MB of kernel cache and the precision
% parameter epsilon=1e-5.
%
% For more details on LIBSVM solver see http://www.csie.ntu.edu.tw/~cjlin/libsvm/

% LibSVM Multiclass
print LibSVMMulticlass

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_multiclass.dat
new_classifier LIBSVM_MULTICLASS
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_libsvmoneclass.sg
% In this example a one-class support vector machine classifier is trained on a
% toy data set. The training algorithm finds a hyperplane in the RKHS which
% separates the training data from the origin. The one-class classifier is
% typically used to estimate the support of a high-dimesnional distribution.
% For more details see e.g.
%   B. Schoelkopf et al. Estimating the support of a high-dimensional
%   distribution. Neural Computation, 13, 2001, 1443-1471.
%
% In the example, the one-class SVM is trained by the LIBSVM solver with the
% regularization parameter C=1.2 and the Gaussian kernel of width 2.1 and the
% precision parameter epsilon=1e-5 and 10MB of the kernel cache.
%
% For more details on LIBSVM solver see http://www.csie.ntu.edu.tw/~cjlin/libsvm/ .
%
%

% LibSVM OneClass
print LibSVMOneClass

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier LIBSVM_ONECLASS
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_mpdsvm.sg
% In this example a two-class support vector machine classifier is trained on a
% toy data set and the trained classifier is used to predict labels of test
% examples. As training algorithm the Minimal Primal Dual SVM is used with SVM
% regularization parameter C=1.2 and a Gaussian kernel of width 2.1 and 10MB of
% kernel cache and the precision parameter epsilon=1e-5.
%
% For more details on the MPD solver see
%  Kienzle, W. and B. Schölkopf: Training Support Vector Machines with Multiple
%  Equality Constraints. Machine Learning: ECML 2005, 182-193. (Eds.) Carbonell,
%  J. G., J. Siekmann, Springer, Berlin, Germany (11 2005)

% MPDSVM
print MPDSVM

set_kernel GAUSSIAN REAL 10 1.2
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier MPDSVM
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_real.dat
out.txt = classify

• examples/documented/cmdline_static/classifier_perceptron.sg
% This example shows how to use the Perceptron algorithm for training a
% two-class linear classifier, i.e.  y = sign( <x,w>+b). The Perceptron algorithm
% works by iteratively passing though the training examples and applying the
% update rule on those examples which are misclassified by the current
% classifier. The Perceptron update rule reads
%
%   w(t+1) = w(t) + alpha * y_t * x_t
%   b(t+1) = b(t) + alpha * y_t
%
% where (x_t,y_t) is feature vector and label (must be +1/-1) of the misclassified example
%       (w(t),b(t)) are the current parameters of the linear classifier
%       (w(t+1),b(t+1)) are the new parameters of the linear classifier
%       alpha is the learning rate.
%
% The Perceptron algorithm iterates until all training examples are correctly
% classified or the prescribed maximal number of iterations is reached.
%
% The learning rate and the maximal number of iterations can be set by
%   sg('set_perceptron_parameters', alpha, max_iter);
%

% Perceptron
print Perceptron

%set_features TRAIN ../data/fm_train_real.dat
%set_labels TRAIN ../data/label_train_twoclass.dat
%new_classifier PERCEPTRON
%set_perceptron_parameters 1.6 5000
%train_classifier

%set_features TEST fm_test_real
%out.txt = classify


• examples/documented/cmdline_static/classifier_svmlight.sg
% In this example a two-class support vector machine classifier is trained on a
% DNA splice-site detection data set and the trained classifier is used to predict
% labels on test set. As training algorithm SVM^light is used with SVM
% regularization parameter C=1.2 and the Weighted Degree kernel of degree 20 and
% the precision parameter epsilon=1e-5.
%
% For more details on the SVM^light see
%  T. Joachims. Making large-scale SVM learning practical. In Advances in Kernel
%  Methods -- Support Vector Learning, pages 169-184. MIT Press, Cambridge, MA USA, 1999.
%
% For more details on the Weighted Degree kernel see
%  G. Raetsch, S.Sonnenburg, and B. Schoelkopf. RASE: recognition of alternatively
%  spliced exons in C. elegans. Bioinformatics, 21:369-377, June 2005.

% SVMLight
%try
print SVMLight

set_kernel WEIGHTEDDEGREE CHAR 10 20
set_features TRAIN ../data/fm_train_dna.dat DNA
set_labels TRAIN ../data/label_train_dna.dat
new_classifier LIGHT
svm_epsilon 1e-5
svm_use_bias 0
c 0.017

train_classifier

set_features TEST ../data/fm_test_dna.dat DNA
out.txt = classify
! rm out.txt
%catch
%	print No support for SVMLight available.
%end

• examples/documented/cmdline_static/classifier_svmlin.sg
% In this example a two-class linear support vector machine classifier is trained
% on a toy data set and the trained classifier is used to predict labels of
% test examples. As training algorithm the SVMLIN solver is used with the SVM
% regularization parameter C=1.2 and the bias term in the classification rule
% switched off. The solver iterates until it finds the epsilon-precise solution
% (epsilon=1e-5) or the maximal training time (max_train_time=60 seconds) is exceeded.
%
% For more details on the SVMLIN solver see
%  V. Sindhwani, S.S. Keerthi. Newton Methods for Fast Solution of Semi-supervised
%  Linear SVMs. Large Scale Kernel Machines MIT Press (Book Chapter), 2007

% SVMLin
print SVMLin

set_features TRAIN ../data/fm_train_sparsereal.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier SVMLIN
svm_epsilon 1e-5
svm_use_bias 0
c 0.42

train_classifier

set_features TEST ../data/fm_test_sparsereal.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_svmocas.sg
% In this example a two-class linear support vector machine classifier is trained
% on a toy data set and the trained classifier is used to predict labels of
% test examples. As training algorithm the OCAS solver is used with the SVM
% regularization parameter C=1.2 and the bias term in the classification rule
% switched off. The solver iterates until the relative duality gap falls below
% epsilon=1e-5 or the maximal training time (max_train_time=60 seconds) is
% exceeded.
%
% For more details on the OCAS solver see
%  V. Franc, S. Sonnenburg. Optimized Cutting Plane Algorithm for Large-Scale Risk
%  Minimization.The Journal of Machine Learning Research, vol. 10,
%  pp. 2157--2192. October 2009.
%

% SVMOcas
print SVMOcas

set_features TRAIN ../data/fm_train_sparsereal.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier SVMOCAS
svm_epsilon 1e-5
svm_use_bias 0
c 0.42

train_classifier

set_features TEST ../data/fm_test_sparsereal.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/classifier_svmsgd.sg
% In this example a two-class linear support vector machine classifier is trained
% on a toy data set and the trained classifier is then used to predict labels of
% test examples. As training algorithm the Stochastic Gradient Descent (SGD)
% solver is used with the SVM regularization parameter C=1.2 and the bias term in the
% classification rule switched off. The solver iterates until the maximal
% training time (max_train_time=60 seconds) is exceeded.
%
% For more details on the SGD solver see
%  L. Bottou, O. Bousquet. The tradeoff of large scale learning. In NIPS 20. MIT
%  Press. 2008.

% SVMSGD
print SVMSGD
%
set_features TRAIN ../data/fm_train_sparsereal.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_classifier SVMSGD
svm_epsilon 1e-5
svm_use_bias 0
c 0.42

train_classifier

set_features TEST ../data/fm_test_sparsereal.dat
out.txt = classify
! rm out.txt


# Clustering

• examples/documented/cmdline_static/clustering_hierarchical.sg
% In this example an agglomerative hierarchical single linkage clustering method
% is used to cluster a given toy data set. Starting with each object being
% assigned to its own cluster clusters are iteratively merged. Here the clusters
% are merged that have the closest (minimum distance, here set via the Euclidean
% distance object) two elements.

% Hierarchical
print Hierarchical

set_features TRAIN  ../data/fm_train_real.dat
set_distance EUCLIDEAN REAL
new_clustering HIERARCHICAL

train_clustering 3
merge_distance.txt, pairs.txt = get_clustering

• examples/documented/cmdline_static/clustering_kmeans.sg
% In this example the k-means clustering method is used to cluster a given toy
% data set. In k-means clustering one tries to partition n observations into k
% clusters in which each observation belongs to the cluster with the nearest mean.
% The algorithm class constructor takes the number of clusters and a distance to
% be used as input. The distance used in this example is Euclidean distance.
% After training one can fetch the result of clustering by obtaining the cluster

% KMEANS
print KMeans

set_features TRAIN ../data/fm_train_real.dat
set_distance EUCLIDEAN REAL
new_clustering KMEANS

train_clustering 3 1000


# Distance

• examples/documented/cmdline_static/distance_braycurtis.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'BRAYCURTIS'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance matrix is computed by
% 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance matrix between
% these two matrices is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CBrayCurtisDistance.html.
%
% Obviously, using the Bray Curtis distance is not limited to this showcase
% example.

% BrayCurtis Distance
print BrayCurtis Distance
set_distance BRAYCURTIS REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_canberra.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'CANBERRA'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance (dissimilarity ratio) matrix is
% computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance (dissimilarity ratio)
% matrix between these two data sets is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CCanberraMetric.html.
%
% Obviously, using the Canberra distance is not limited to this showcase
% example.

% Canberra Metric
print CanberraMetric
set_distance CANBERRA REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_canberraword.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored data sets in 'STRING' representation
% (feature type 'CHAR' with alphabet 'DNA') from different files and
% initializes the distance to 'CANBERRA' with feature type 'WORD'.
%
% Data points in this example are defined by the transformation function
% 'convert' and the preprocessing step applied afterwards (defined by
%
% The target 'TRAIN' for 'set_features' controls the binding of the given
% data points. In order to compute a pairwise distance matrix by
% 'get_distance_matrix', we have to perform two preprocessing steps for
% input data 'TRAIN'. The method 'convert' transforms the input data to
% a string representation suitable for the selected distance. The individual
% strings are sorted in ascending order after the execution of 'attach_preproc'.
% A pairwise distance matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the binding of the given
% data points 'TRAIN' and 'TEST'. In order to compute a pairwise distance
% matrix between these two data sets by 'get_distance_matrix', we have to
% perform two preprocessing steps for input data 'TEST'. The method 'convert'
% transforms the input data 'TEST' to a string representation suitable for
% the selected distance. The individual strings are sorted in ascending order
% after the execution of 'attach_preproc'. A pairwise distance matrix between
% the data sets 'TRAIN' and 'TEST' is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see
% doc/classshogun_1_1CSortWordString.html,
% doc/classshogun_1_1CPreprocessor.html,
% doc/classshogun_1_1CStringFeatures.html (method obtain_from_char_features) and
% doc/classshogun_1_1CCanberraWordDistance.html.
%
% Obviously, using the Canberra word distance is not limited to this showcase
% example.

% CanberraWord Distance
print CanberraWordDistance

set_distance CANBERRA WORD

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_chebyshew.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'CHEBYSHEW'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance matrix (maximum of absolute feature
% dimension differences) is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance matrix (maximum
% of absolute feature dimension differences) between these two data sets is
% computed.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CChebyshewMetric.html.
%
% Obviously, using the Chebyshew distance is not limited to this showcase
% example.

% Chebyshew Metric
print ChebyshewMetric
set_distance CHEBYSHEW REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_chisquare.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'CHISQUARE'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance matrix is computed by
% 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance matrix between
% these two matrices is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CChiSquareDistance.html.
%
% Obviously, using the ChiSquare distance is not limited to this showcase
% example.

% ChiSquare Distance
print ChiSquareDistance
set_distance CHISQUARE REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_cosine.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'COSINE'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance matrix is computed by
% 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance matrix between
% these two data sets is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CCosineDistance.html.
%
% Obviously, using the Cosine distance is not limited to this showcase
% example.

% Cosine Distance
print CosineDistance
set_distance COSINE REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_euclidean.sg
% Euclidean Distance
print EuclideanDistance
set_distance EUCLIDEAN REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_geodesic.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'GEODESIC'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance (shortest path on a sphere) matrix is
% computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance (shortest path on
% a sphere) matrix between these two data sets is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CGeodesicMetric.html.
%
% Obviously, using the Geodesic distance is not limited to this showcase
% example.

% Geodesic Metric
print GeodesicMetric
set_distance GEODESIC REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_hammingword.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored data sets in 'STRING' representation
% (feature type 'CHAR' with alphabet 'DNA') from different files and
% initializes the distance to 'HAMMING' with feature type 'WORD'.
%
% Data points in this example are defined by the transformation function
% 'convert' and the preprocessing step applied afterwards (defined by
%
% The target 'TRAIN' for 'set_features' controls the binding of the given
% data points. In order to compute a pairwise distance matrix by
% 'get_distance_matrix', we have to perform two preprocessing steps for
% input data 'TRAIN'. The method 'convert' transforms the input data to
% a string representation suitable for the selected distance. The individual
% strings are sorted in ascending order after the execution of 'attach_preproc'.
% A pairwise distance matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the binding of the given
% data points 'TRAIN' and 'TEST'. In order to compute a pairwise distance
% matrix between these two data sets by 'get_distance_matrix', we have to
% perform two preprocessing steps for input data 'TEST'. The method 'convert'
% transforms the input data 'TEST' to a string representation suitable for
% the selected distance. The individual strings are sorted in ascending order
% after the execution of 'attach_preproc'. A pairwise distance matrix between
% the data sets 'TRAIN' and 'TEST' is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see
% doc/classshogun_1_1CSortWordString.html,
% doc/classshogun_1_1CPreprocessor.html,
% doc/classshogun_1_1CStringFeatures.html (method obtain_from_char_features) and
% doc/classshogun_1_1CHammingWordDistance.html.
%
% Obviously, using the Hamming word distance is not limited to this showcase
% example.

% HammingWord Distance
print HammingWordDistance

set_distance HAMMING WORD

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_jensen.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'JENSEN'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance (divergence measure based on the
% Kullback-Leibler divergence) matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance (divergence measure
% based on the Kullback-Leibler divergence) matrix between these two data sets
% is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CJensenMetric.html.
%
% Obviously, using the Jensen-Shannon distance/divergence is not limited to
% this showcase example.

% Jensen Metric
print JensenMetric
set_distance JENSEN REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_manhatten.sg
% n approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'MANHATTAN'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance (sum of absolute feature
% dimension differences) matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance (sum of absolute
% feature dimension differences) matrix between these two data sets is
% computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CManhattanMetric.html.
%
% Obviously, using the Manhattan distance is not limited to this showcase
% example.

% Manhattan Metric
print ManhattanMetric
set_distance MANHATTAN REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_manhattenword.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored data sets in 'STRING' representation
% (feature type 'CHAR' with alphabet 'DNA') from different files and
% initializes the distance to 'MANHATTAN' with feature type 'WORD'.
%
% Data points in this example are defined by the transformation function
% 'convert' and the preprocessing step applied afterwards (defined by
%
% The target 'TRAIN' for 'set_features' controls the binding of the given
% data points. In order to compute a pairwise distance matrix by
% 'get_distance_matrix', we have to perform two preprocessing steps for
% input data 'TRAIN'. The method 'convert' transforms the input data to
% a string representation suitable for the selected distance. The individual
% strings are sorted in ascending order after the execution of 'attach_preproc'.
% A pairwise distance matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the binding of the given
% data points 'TRAIN' and 'TEST'. In order to compute a pairwise distance
% matrix between these two data sets by 'get_distance_matrix', we have to
% perform two preprocessing steps for input data 'TEST'. The method 'convert'
% transforms the input data 'TEST' to a string representation suitable for
% the selected distance. The individual strings are sorted in ascending order
% after the execution of 'attach_preproc'. A pairwise distance matrix between
% the data sets 'TRAIN' and 'TEST' is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see
% doc/classshogun_1_1CSortWordString.html,
% doc/classshogun_1_1CPreprocessor.html,
% doc/classshogun_1_1CStringFeatures.html (method obtain_from_char_features) and
% doc/classshogun_1_1CManhattanWordDistance.html.
%
% Obviously, using the Manhattan word distance is not limited to this showcase
% example.

% ManhattanWord Distance
print ManhattanWordDistance

set_distance MANHATTAN WORD

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_minkowski.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'MINKOWSKI' with
% norm 'k'. Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance matrix is computed by
% 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance matrix between
% these two data sets is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CMinkowskiMetric.html.
%
% Obviously, using the Minkowski metric is not limited to this showcase
% example.

% Minkowski Metric
print MinkowskiMetric
set_distance MINKOWSKI REAL 3

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST

• examples/documented/cmdline_static/distance_tanimoto.sg
% An approach as applied below, which shows the processing of input data
% from a file becomes a crucial factor for writing your own sample applications.
% This approach is just one example of what can be done using the distance
% functions provided by shogun.
%
% First, you need to determine what type your data will be, because this
% will determine the distance function you can use.
%
% This example loads two stored matrices of real values (feature type 'REAL')
% from different files and initializes the distance to 'TANIMOTO'.
% Each column of the matrices corresponds to one data point.
%
% The target 'TRAIN' for 'set_features' controls the processing of the given
% data points, where a pairwise distance (extended Jaccard coefficient)
% matrix is computed by 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix' and
% target 'TRAIN'.
%
% The target 'TEST' for 'set_features' controls the processing of the given
% data points 'TRAIN' and 'TEST', where a pairwise distance (extended
% Jaccard coefficient) matrix between these two data sets is computed by
% 'get_distance_matrix'.
%
% The resulting distance matrix can be reaccessed by 'get_distance_matrix'
% and target 'TEST'. The 'TRAIN' distance matrix ceased to exist.
%
% For more details see doc/classshogun_1_1CTanimotoDistance.html.
%
% Obviously, using the Tanimoto distance/coefficient is not limited to
% this showcase example.

% Tanimoto Distance
print TanimotoDistance
set_distance TANIMOTO REAL

set_features TRAIN ../data/fm_train_real.dat
dm_train.txt = get_distance_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
dm_test.txt = get_distance_matrix TEST


# Distribution

• examples/documented/cmdline_static/distribution_histogram.sg
% In this example the Histogram algorithm object computes a histogram over all
% 16bit unsigned integers in the features.

% Histogram
print Histogram - not yet supported

%new_distribution HISTOGRAM

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN

%train_distribution
%histo.txt = get_histogram

%get_log_likelihood
%get_log_likelihood_sample

• examples/documented/cmdline_static/distribution_hmm.sg
% In this example a hidden markov model with 3 states and 6 transitions is trained
% on a string data set.

% HMM
print HMM

new_hmm 3 6
set_features TRAIN ../data/fm_train_cube.dat CUBE
convert TRAIN STRING CHAR STRING WORD 1
bw
p.txt, q.txt, a.txt, b.txt = get_hmm

%new_hmm 3 6
%set_hmm p.txt q.txt a.txt b.txt
%likelihood.txt = hmm_likelihood

• examples/documented/cmdline_static/distribution_linearhmm.sg
% Trains an inhomogeneous Markov chain of order 3 on a DNA string data set. Due to
% the structure of the Markov chain it is very similar to a HMM with just one
% chain of connected hidden states - that is why we termed this linear HMM.

% LinearHMM
print LinearHMM - not yet supported

%new_distribution LinearHMM

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN

%train_distribution
%histo.txt = get_histogram

%get_log_likelihood
%get_log_likelihood_sample


# Kernel

• examples/documented/cmdline_static/kernel_chi2.sg
% This is an example for the initialization of the chi2-kernel on real data, where
% each column of the matrices corresponds to one training/test example.

% CHI2
print Chi2
set_kernel CHI2 REAL 10 1.4

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_combined.sg
% This is an example for the initialization of a combined kernel, which is a weighted sum of
% in this case three kernels on real valued data. The sub-kernel weights are all set to 1.
%

% Combined
print Combined
clean_features TRAIN
clean_features TEST
set_kernel COMBINED 10

add_kernel 1 GAUSSIAN REAL 10 1.

add_kernel 1 POLY REAL 10 3 0

km_train.txt = get_kernel_matrix TRAIN

km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_commulongstring.sg
% This is an example for the initialization of the CommUlongString-kernel. This kernel
% sums over k-mere matches (k='order'). For efficient computing a preprocessor is used
% that extracts and sorts all k-mers. If 'use_sign' is set to one each k-mere is counted
% only once.

% Comm Ulong String
print CommUlongString
set_kernel COMMSTRING ULONG 10 0 FULL

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING ULONG 3 2 0 n
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING ULONG 3 2 0 n
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_commwordstring.sg
% This is an example for the initialization of the CommWordString-kernel (aka
% Spectrum or n-gram kernel; its name is derived from the unix command comm). This kernel
% sums over k-mere matches (k='order'). For efficient computing a preprocessor is used
% that extracts and sorts all k-mers. If 'use_sign' is set to one each k-mere is counted
% only once.

% Comm Word String
print CommWordString
set_kernel COMMSTRING WORD 10 0 FULL

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_const.sg
% The constant kernel gives a trivial kernel matrix with all entries set to the same value
% defined by the argument 'c'.
%

% Const
print Const

set_kernel CONST REAL 10 23

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_diag.sg
% This is an example for the initialization of the diag-kernel.
% The diag kernel has all kernel matrix entries but those on
% the main diagonal set to zero.

% Diag
print Diag
set_kernel DIAG REAL 10 23.

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_distance.sg
% With the distance kernel one can use any of the following distance metrics:
% MINKOWSKI MANHATTAN HAMMING CANBERRA CHEBYSHEW GEODESIC JENSEN CHISQUARE TANIMOTO COSINE BRAYCURTIS EUCLIDIAN

% Distance
print Distance
set_distance EUCLIDEAN REAL
set_kernel DISTANCE 10 1.7

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_fixeddegreestring.sg
% The FixedDegree String kernel takes as input two strings of same size and counts the number of matches of length d.

% Fixed Degree String
print FixedDegreeString
set_kernel FIXEDDEGREE CHAR 10 3

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_gaussian.sg
% The well known Gaussian kernel (swiss army knife for SVMs) on dense real valued features.

% Gaussian
print Gaussian
set_kernel GAUSSIAN REAL 10 1.4

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_gaussianshift.sg
% An experimental kernel inspired by the WeightedDegreePositionStringKernel and the Gaussian kernel.
% The idea is to shift the dimensions of the input vectors against eachother. 'shift_step' is the step
% size of the shifts and  max_shift is the maximal shift.

% GaussianShift
print GaussianShift
set_kernel GAUSSIANSHIFT REAL 10 1.4 2 1

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_linear.sg
% This is an example for the initialization of a linear kernel on real valued
% data using scaling factor 1.2.

% Linear
print Linear
set_kernel LINEAR REAL 10 1.2

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_linearbyte.sg
% This is an example for the initialization of a linear kernel on raw byte
% data.

% LinearByte is b0rked
print LinearByte

%set_kernel LINEAR BYTE size_cache

%set_features TRAIN ../data/fm_train_byte.dat RAWBYTE
%km_train.txt = get_kernel_matrix TRAIN

%set_features TEST ../data/fm_test_byte.dat RAWBYTE
%km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_linearstring.sg
% This is an example for the initialization of a linear kernel on string data. The
% strings are all of the same length and consist of the characters 'ACGT' corresponding
% to the DNA-alphabet. Each column of the matrices of type char corresponds to
% one training/test example.

% Linear String
print LinearString
set_kernel LINEAR CHAR 10

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_linearword.sg
% This is an example for the initialization of a linear kernel on word (2byte)
% data.

% LinearWord
%print LinearWord
%set_kernel LINEAR WORD 10 1.4

%set_features TRAIN ../data/fm_train_word.dat
%km_train.txt = get_kernel_matrix TRAIN

%set_features TEST ../data/fm_test_word.dat
%km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_localalignmentstring.sg
% This is an example for the initialization of the local alignment kernel on
% DNA sequences, where each column of the matrices of type char corresponds to
% one training/test example.

% Local Alignment String
%print LocalAlignmentString
%set_kernel LOACALALIGNMENT CHAR 10

%set_features TRAIN ../data/fm_train_dna.dat DNA
%km_train.txt = get_kernel_matrix TRAIN

%set_features TEST ../data/fm_test_dna.dat DNA
%km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_localityimprovedstring.sg
% This example initializes the locality improved string kernel. The locality improved string
% kernel is defined on sequences of the same length and inspects letters matching at
% corresponding positions in both sequences. The kernel sums over all matches in windows of
% length l and takes this sum to the power of 'inner_degree'. The sum over all these
% terms along the sequence is taken to the power of 'outer_degree'.

% Locality Improved String
print LocalityImprovedString
set_kernel LIK CHAR 10 5 5 7

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_oligostring.sg
% This is an example initializing the oligo string kernel which takes distances
% between matching oligos (k-mers) into account via a gaussian. Variable 'k' defines the length
% of the oligo and variable 'w' the width of the gaussian. The oligo string kernel is
% implemented for the DNA-alphabet 'ACGT'.
%

% Oligo String
print Oligo
set_kernel OLIGO CHAR 10 3 1.2

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_poly.sg
% This example initializes the polynomial kernel with real data.
% If variable 'inhomogene' is 'true' +1 is added to the scalar product
% before taking it to the power of 'degree'. If 'use_normalization' is
% set to 'true' then kernel matrix will be normalized by the square roots
% of the diagonal entries.

% Poly
print Poly
set_kernel POLY REAL 10 4 0 1

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_polymatchstring.sg
% This is an example for the initialization of the PolyMatchString kernel on string data.
% The PolyMatchString kernel sums over the matches of two stings of the same length and
% takes the sum to the power of 'degree'. The strings consist of the characters 'ACGT' corresponding
% to the DNA-alphabet. Each column of the matrices of type char corresponds to
% one training/test example.

% Poly Match String
print PolyMatchString
set_kernel POLYMATCH CHAR 10 3 0

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_polymatchword.sg
% The PolyMatchWordString kernel is defined on strings of equal length.
% The kernel sums over the matches of two stings of the same length and
% takes the sum to the power of 'degree'. The strings in this example
% consist of the characters 'ACGT' corresponding to the DNA-alphabet. Each
% column of the matrices of type char corresponds to one training/test example.

% Poly Match Word
%print PolyMatchWord
%set_kernel POLYMATCH WORD 10 2 1 1

%set_features TRAIN ../data/fm_train_word.dat
%km_train.txt = get_kernel_matrix TRAIN

%set_features TEST ../data/fm_test_word.dat
%km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_sigmoid.sg
% The standard Sigmoid kernel computed on dense real valued features.

% sigmoid
print Sigmoid
set_kernel SIGMOID REAL 10 1.2 1.3

set_features TRAIN ../data/fm_train_real.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_simplelocalityimprovedstring.sg
% SimpleLocalityImprovedString kernel, is a simplified'' and better performing version of the Locality improved kernel.

% Simple Locality Improved String
print SimpleLocalityImprovedString
set_kernel SLIK CHAR 10 5 5 7

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_sparsegaussian.sg
% The well known Gaussian kernel (swiss army knife for SVMs) on sparse real valued features.

% Sparse Gaussian
print SparseGaussian
set_kernel GAUSSIAN SPARSEREAL 10 1.4

set_features TRAIN ../data/fm_train_sparsereal.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_sparsereal.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_sparselinear.sg
% Computes the standard linear kernel on sparse real valued features.

% Sparse Linear
print SparseLinear
set_kernel LINEAR SPARSEREAL 10 1.3

set_features TRAIN ../data/fm_train_sparsereal.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_sparsereal.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_sparsepoly.sg
% Computes the standard polynomial kernel on sparse real valued features.

% Sparse Poly
print SparsePoly
set_kernel POLY SPARSEREAL 10 3 1 1

set_features TRAIN ../data/fm_train_sparsereal.dat
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_sparsereal.dat
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_top.sg
% The class TOPFeatures implements TOP kernel features obtained from
% two Hidden Markov models.
%
% It was used in
%
% K. Tsuda, M. Kawanabe, G. Raetsch, S. Sonnenburg, and K.R. Mueller. A new
% discriminative kernel from probabilistic models. Neural Computation,
% 14:2397-2414, 2002.
%
% which also has the details.
%
% Note that TOP-features are computed on the fly, so to be effective feature
% caching should be enabled.
%
% It inherits its functionality from CSimpleFeatures, which should be
% consulted for further reference.
%

% Plugin Estimate
print PluginEstimate w/ HistogramWord

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n

new_plugin_estimator 1e-1 1e-1
set_labels TRAIN ../data/label_train_dna.dat
train_estimator

set_kernel HISTOGRAM WORD 10
km_train.txt = get_kernel_matrix TRAIN

% not supported yet;
%	lab.txt = plugin_estimate_classify
km_text.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_weightedcommwordstring.sg
% The WeightedCommWordString kernel may be used to compute the weighted
% spectrum kernel (i.e. a spectrum kernel for 1 to K-mers, where each k-mer
% length is weighted by some coefficient \f$\beta_k\f$) from strings that have
% been mapped into unsigned 16bit integers.
%
% These 16bit integers correspond to k-mers. To applicable in this kernel they
% need to be sorted (e.g. via the SortWordString pre-processor).
%
% It basically uses the algorithm in the unix "comm" command (hence the name)
% to compute:
%
% k({\bf x},({\bf x'})= \sum_{k=1}^K\beta_k\Phi_k({\bf x})\cdot \Phi_k({\bf x'})
%
% where \f$\Phi_k\f$ maps a sequence \f${\bf x}\f$ that consists of letters in
% \f$\Sigma\f$ to a feature vector of size \f$|\Sigma|^k\f$. In this feature
% vector each entry denotes how often the k-mer appears in that \f${\bf x}\f$.
%
% Note that this representation is especially tuned to small alphabets
% (like the 2-bit alphabet DNA), for which it enables spectrum kernels
% of order 8.
%
% For this kernel the linadd speedups are quite efficiently implemented using
% direct maps.
%

% Weighted Comm Word String
print WeightedCommWordString
set_kernel WEIGHTEDCOMMSTRING WORD 10 0 FULL

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_weighteddegreepositionstring.sg
% The Weighted Degree Position String kernel (Weighted Degree kernel with shifts).
%
% The WD-shift kernel of order d compares two sequences X and
% Y of length L by summing all contributions of k-mer matches of
% lengths k in 1...d, weighted by coefficients beta_k
% allowing for a positional tolerance of up to shift s.
%

% Weighted Degree Position String
print WeightedDegreePositionString
set_kernel WEIGHTEDDEGREEPOS CHAR 10 20

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/kernel_weighteddegreestring.sg
% The Weighted Degree String kernel.
%
% The WD kernel of order d compares two sequences X and
% Y of length L by summing all contributions of k-mer matches of
% lengths k in 1...d , weighted by coefficients beta_k. It
% is defined as
%
%     k(X, Y)=\sum_{k=1}^d\beta_k\sum_{l=1}^{L-k+1}I(u_{k,l}(X)=u_{k,l}(Y)).
%
% Here, $u_{k,l}(X)$ is the string of length k starting at position
% l of the sequence X and I(.) is the indicator function
% which evaluates to 1 when its argument is true and to 0
% otherwise.
%

% Weighted Degree String
print WeightedDegreeString
set_kernel WEIGHTEDDEGREE CHAR 10 20

set_features TRAIN ../data/fm_train_dna.dat DNA
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
km_test.txt = get_kernel_matrix TEST


# Mkl

• examples/documented/cmdline_static/mkl_multiclass.sg
% MKL_Multiclass
print MKL_Multiclass

set_labels TRAIN ../data/label_train_multiclass.dat

clean_features TRAIN
clean_features TEST
set_kernel COMBINED 10

add_kernel 1 GAUSSIAN REAL 10 1.2

add_kernel 1 POLY REAL 10 2 0

new_classifier MKL_MULTICLASS
mkl_parameters 0.001 1 1.5
svm_epsilon 1e-5
c 1.2
train_classifier

out.txt = classify
! rm out.txt


# Preproc

• examples/documented/cmdline_static/preproc_logplusone.sg
% In this example a kernel matrix is computed for a given real-valued data set.
% The kernel used is the Chi2 kernel which operates on real-valued vectors. It
% computes the chi-squared distance between sets of histograms. It is a very
% useful distance in image recognition (used to detect objects). The preprocessor
% LogPlusOne adds one to a dense real-valued vector and takes the logarithm of
% each component of it. It is most useful in situations where the inputs are
% counts: When one compares differences of small counts any difference may matter
% a lot, while small differences in large counts don't. This is what this log
% transformation controls for.

% LogPlusOne
print LogPlusOne
set_kernel CHI2 REAL 10 1.4

set_features TRAIN ../data/fm_train_real.dat
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/preproc_normone.sg
% In this example a kernel matrix is computed for a given real-valued data set.
% The kernel used is the Chi2 kernel which operates on real-valued vectors. It
% computes the chi-squared distance between sets of histograms. It is a very
% useful distance in image recognition (used to detect objects). The preprocessor
% NormOne, normalizes vectors to have norm 1.

% NormOne
print NormOne
set_kernel CHI2 REAL 10 1.4

set_features TRAIN ../data/fm_train_real.dat
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/preproc_prunevarsubmean.sg
% In this example a kernel matrix is computed for a given real-valued data set.
% The kernel used is the Chi2 kernel which operates on real-valued vectors. It
% computes the chi-squared distance between sets of histograms. It is a very
% useful distance in image recognition (used to detect objects). The preprocessor
% PruneVarSubMean substracts the mean from each feature and removes features that
% have zero variance.

% PruneVarSubMean
print PruneVarSubMean
set_kernel CHI2 REAL 10 1.4

set_features TRAIN ../data/fm_train_real.dat
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_real.dat
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/preproc_sortulongstring.sg
% In this example a kernel matrix is computed for a given string data set. The
% CommUlongString kernel is used to compute the spectrum kernel from strings that
% have been mapped into unsigned 64bit integers. These 64bit integers correspond
% to k-mers. To be applicable in this kernel the mapped k-mers have to be sorted.
% This is done using the SortUlongString preprocessor, which sorts the indivual
% strings in ascending order. The kernel function basically uses the algorithm in
% the unix "comm" command (hence the name). Note that this representation enables
% spectrum kernels of order 8 for 8bit alphabets (like binaries) and order 32 for
% 2-bit alphabets like DNA. For this kernel the linadd speedups are implemented
% (though there is room for improvement here when a whole set of sequences is

% SortUlongString
print CommUlongString
set_kernel COMMSTRING ULONG 10 0 FULL

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING ULONG 3 2 0 n
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING ULONG 3 2 0 n
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST

• examples/documented/cmdline_static/preproc_sortwordstring.sg
% In this example a kernel matrix is computed for a given string data set. The
% CommWordString kernel is used to compute the spectrum kernel from strings that
% have been mapped into unsigned 16bit integers. These 16bit integers correspond
% to k-mers. To be applicable in this kernel the mapped k-mers have to be sorted.
% This is done using the SortWordString preprocessor, which sorts the indivual
% strings in ascending order. The kernel function basically uses the algorithm in
% the unix "comm" command (hence the name). Note that this representation is
% especially tuned to small alphabets (like the 2-bit alphabet DNA), for which it
% enables spectrum kernels of order up to 8. For this kernel the linadd speedups
% are quite efficiently implemented using direct maps.

% SortWordString
print CommWordString
set_kernel COMMSTRING WORD 10 0 FULL

set_features TRAIN ../data/fm_train_dna.dat DNA
convert TRAIN STRING CHAR STRING WORD 3 2 0 n
attach_preproc TRAIN
km_train.txt = get_kernel_matrix TRAIN

set_features TEST ../data/fm_test_dna.dat DNA
convert TEST STRING CHAR STRING WORD 3 2 0 n
attach_preproc TEST
km_test.txt = get_kernel_matrix TEST


# Regression

• examples/documented/cmdline_static/regression_krr.sg
% In this example a kernelized version of ridge regression (KRR) is trained on a
% real-valued data set. The KRR is trained with regularization parameter tau=1e-6
% and a gaussian kernel with width=0.8.

% kernel ridge regression
print Kernel Ridge Regression
set_kernel GAUSSIAN REAL 10 2.1
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_regression.dat
new_regression KERNELRIDGEREGRESSION
krr_tau 1.2
c 0.017

train_regression

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/regression_libsvr.sg
% In this example a support vector regression algorithm is trained on a
% real-valued toy data set. The underlying library used for the SVR training is
% LIBSVM. The SVR is trained with regularization parameter C=1 and a gaussian
% kernel with width=2.1.
%
% For more details on LIBSVM solver see http://www.csie.ntu.edu.tw/~cjlin/libsvm/ .

% LibSVR
print LibSVR
set_kernel GAUSSIAN REAL 10 2.1
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_regression.dat
new_regression LIBSVR
svr_tube_epsilon 1e-2
c 0.017

train_regression

set_features TEST ../data/fm_test_real.dat
out.txt = classify
! rm out.txt

• examples/documented/cmdline_static/regression_svrlight.sg
% In this example a support vector regression algorithm is trained on a
% real-valued toy data set. The underlying library used for the SVR training is
% SVM^light. The SVR is trained with regularization parameter C=1 and a gaussian
% kernel with width=2.1.
%
% For more details on the SVM^light see
%  T. Joachims. Making large-scale SVM learning practical. In Advances in Kernel
%  Methods -- Support Vector Learning, pages 169-184. MIT Press, Cambridge, MA USA, 1999.

% SVR Light
%try
print SVRLight

set_kernel GAUSSIAN REAL 10 2.1
set_features TRAIN ../data/fm_train_real.dat
set_labels TRAIN ../data/label_train_twoclass.dat
new_regression SVRLIGHT
svr_tube_epsilon 1e-2
c 0.017

train_regression

set_features TEST ../data/fm_test_real.dat
svrlight_out.txt = classify
! rm svrlight_out.txt
%catch
%	disp('No support for SVRLight available.')
%end


SHOGUN Machine Learning Toolbox - Documentation