Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Soeren Sonnenburg
committed
Mar 26, 2012
1 parent
97e8e21
commit dfbb2fd
Showing
9 changed files
with
185 additions
and
4 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
examples/undocumented/python_modular/kernel_director_modular.py
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,65 @@ | ||
#import numpy | ||
#from _modshogun import DirectorKernel,Labels,CombinedKernel | ||
# | ||
#class MyKernel(DirectorKernel): | ||
# def init(self, f1,f2): | ||
# print "hallo" | ||
# return true | ||
# | ||
# def compute(self, i,j): | ||
# print i+j | ||
# return i+j | ||
# | ||
# | ||
# | ||
#from tools.load import LoadMatrix | ||
#lm=LoadMatrix() | ||
## | ||
##traindat = lm.load_numbers('../data/fm_train_real.dat') | ||
##testdat = lm.load_numbers('../data/fm_test_real.dat') | ||
#label_traindat = lm.load_labels('../data/label_train_twoclass.dat') | ||
## | ||
##parameter_list = [[traindat,testdat,label_traindat,2.1,1,1e-5],[traindat,testdat,label_traindat,2.2,1,1e-5]] | ||
## | ||
##def classifier_libsvm_modular (fm_train_real=traindat,fm_test_real=testdat,label_train_twoclass=label_traindat,width=2.1,C=1,epsilon=1e-5): | ||
## from shogun.Features import RealFeatures, Labels | ||
## from shogun.Kernel import GaussianKernel | ||
## from shogun.Classifier import LibSVM | ||
## | ||
## feats_train=RealFeatures(fm_train_real) | ||
## feats_train.parallel.set_num_threads(1) | ||
## feats_test=RealFeatures(fm_test_real) | ||
## | ||
## kernel=MyKernel() | ||
## labels=Labels(label_train_twoclass) | ||
## | ||
## svm=LibSVM(C, kernel, labels) | ||
## svm.set_epsilon(epsilon) | ||
## svm.train() | ||
## | ||
## kernel.init(feats_train, feats_test) | ||
## labels = svm.apply().get_labels() | ||
## supportvectors = sv_idx=svm.get_support_vectors() | ||
## alphas=svm.get_alphas() | ||
## predictions = svm.apply() | ||
## return predictions, svm, predictions.get_labels() | ||
## | ||
##if __name__=='__main__': | ||
## print 'LibSVM' | ||
## classifier_libsvm_modular(*parameter_list[0]) | ||
# | ||
#labels=Labels(label_traindat) | ||
##kernel=DirectorKernel() | ||
#kernel=MyKernel() | ||
#print kernel.get_cache_size() | ||
#print kernel.get_name() | ||
#k=CombinedKernel() | ||
#k.io.set_loglevel(0) | ||
#k.append_kernel(kernel) | ||
## | ||
#k.list_kernels() | ||
## | ||
##svm=LibSVM(0.1, kernel, labels) | ||
##svm.train() | ||
##print kernel.compute(0,0) | ||
# |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Written (W) 2011 Soeren Sonnenburg | ||
* Copyright (C) 2011 Soeren Sonnenburg | ||
*/ | ||
|
||
#ifndef _DIRECTORKERNEL_H___ | ||
#define _DIRECTORKERNEL_H___ | ||
|
||
#include <shogun/lib/common.h> | ||
#include <shogun/kernel/Kernel.h> | ||
|
||
namespace shogun | ||
{ | ||
class CDirectorKernel: public CKernel | ||
{ | ||
public: | ||
/** default constructor | ||
* | ||
*/ | ||
CDirectorKernel() : CKernel() | ||
{ | ||
} | ||
|
||
/** constructor | ||
* | ||
*/ | ||
CDirectorKernel(int32_t size) : CKernel(size) | ||
{ | ||
} | ||
|
||
/** default constructor | ||
* | ||
*/ | ||
virtual ~CDirectorKernel() | ||
{ | ||
cleanup(); | ||
} | ||
|
||
/** initialize kernel | ||
* | ||
* @param l features of left-hand side | ||
* @param r features of right-hand side | ||
* @return if initializing was successful | ||
*/ | ||
virtual bool init(CFeatures* l, CFeatures* r) | ||
{ | ||
} | ||
|
||
/** clean up kernel */ | ||
virtual void cleanup() | ||
{ | ||
} | ||
|
||
/** return what type of kernel we are | ||
* | ||
* @return kernel type DIRECTOR | ||
*/ | ||
virtual EKernelType get_kernel_type() { return K_DIRECTOR; } | ||
|
||
/** return what type of features kernel can deal with | ||
* | ||
* @return feature type ANY | ||
*/ | ||
virtual EFeatureType get_feature_type() { return F_ANY; } | ||
|
||
/** return what class of features kernel can deal with | ||
* | ||
* @return feature class ANY | ||
*/ | ||
virtual EFeatureClass get_feature_class() { return C_ANY; } | ||
|
||
/** return the kernel's name | ||
* | ||
* @return name Director | ||
*/ | ||
inline virtual const char* get_name() const { return "DirectorKernel"; } | ||
|
||
protected: | ||
/** compute kernel function for features a and b | ||
* idx_{a,b} denote the index of the feature vectors | ||
* in the corresponding feature object | ||
* | ||
* @param idx_a index a | ||
* @param idx_b index b | ||
* @return computed kernel function at indices a,b | ||
*/ | ||
virtual float64_t compute(int32_t idx_a, int32_t idx_b) | ||
{ | ||
SG_ERROR("Compute method of Director Kernel needs to be overridden.\n"); | ||
return 0; | ||
} | ||
}; | ||
} | ||
#endif /* _GAUSSIANKERNEL_H__ */ |
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