32 #ifdef USE_SHORTREAL_KERNELCACHE
118 #ifndef DOXYGEN_SHOULD_SKIP_THIS
120 template <
class T>
struct K_THREAD_PARAM
222 SG_ERROR(
"Index out of Range: idx_a=%d/%d idx_b=%d/%d\n",
235 return get_kernel_matrix<float64_t>();
248 for (int32_t i=0; i!=
num_rhs; i++)
264 for (int32_t j=0; j!=
num_lhs; j++)
280 SG_ERROR(
"no features assigned to kernel\n");
285 int64_t total_num = int64_t(m)*n;
288 bool symmetric= (
lhs &&
lhs==
rhs && m==n);
290 SG_DEBUG(
"returning kernel matrix of size %dx%d\n", m, n);
297 K_THREAD_PARAM<T> params;
299 params.result=result;
302 params.total_start=0;
303 params.total_end=total_num;
306 params.symmetric=symmetric;
308 get_kernel_matrix_helper<T>((
void*) ¶ms);
312 pthread_t* threads =
SG_MALLOC(pthread_t, num_threads-1);
313 K_THREAD_PARAM<T>* params =
SG_MALLOC(K_THREAD_PARAM<T>, num_threads);
314 int64_t step= total_num/num_threads;
319 for (t=0; t<num_threads; t++)
321 params[t].kernel =
this;
322 params[t].result = result;
325 params[t].total_start=t*step;
326 params[t].total_end=(t+1)*step;
329 params[t].symmetric=symmetric;
330 params[t].verbose=
false;
332 int code=pthread_create(&threads[t], NULL,
333 CKernel::get_kernel_matrix_helper<T>, (
void*)¶ms[t]);
337 SG_WARNING(
"Thread creation failed (thread %d of %d) "
338 "with error:'%s'\n",t, num_threads, strerror(code));
344 params[t].kernel =
this;
345 params[t].result = result;
348 params[t].total_start=t*step;
349 params[t].total_end=total_num;
352 params[t].symmetric=symmetric;
353 params[t].verbose=
true;
354 get_kernel_matrix_helper<T>(¶ms[t]);
356 for (t=0; t<num_threads; t++)
358 if (pthread_join(threads[t], NULL) != 0)
359 SG_WARNING(
"pthread_join of thread %d/%d failed\n", t, num_threads);
569 int32_t count, int32_t *IDX,
float64_t *weights);
600 int32_t num_vec, int32_t* vec_idx,
float64_t* target,
601 int32_t num_suppvec, int32_t* IDX,
float64_t* alphas,
628 int32_t vector_idx,
float64_t * subkernel_contrib);
693 i_start=(int32_t) (offs/int64_t(n));
705 K_THREAD_PARAM<T>* params= (K_THREAD_PARAM<T>*) p;
706 int32_t i_start=params->start;
707 int32_t i_end=params->end;
709 T* result=params->result;
710 bool symmetric=params->symmetric;
713 bool verbose=params->verbose;
714 int64_t total_start=params->total_start;
715 int64_t total_end=params->total_end;
716 int64_t total=total_start;
718 for (int32_t i=i_start; i<i_end; i++)
725 for (int32_t j=j_start; j<n; j++)
730 if (symmetric && i!=j)
737 if (symmetric && i!=j)
741 k->SG_PROGRESS(total, total_start, total_end);
virtual void clear_normal()
virtual void load_serializable_post()
int32_t compute_row_start(int64_t offs, int32_t n, bool symmetric)
The MultitaskKernel allows Multitask Learning via a modified kernel function.
virtual void compute_by_subkernel(int32_t vector_idx, float64_t *subkernel_contrib)
int32_t get_num_threads() const
virtual float64_t compute(int32_t x, int32_t y)=0
DiceKernelNormalizer performs kernel normalization inspired by the Dice coefficient (see http://en...
The MultitaskKernel allows Multitask Learning via a modified kernel function.
SGMatrix< T > get_kernel_matrix()
int32_t num_rhs
number of feature vectors on right hand side
Class ShogunException defines an exception which is thrown whenever an error inside of shogun occurs...
virtual bool set_normalizer(CKernelNormalizer *normalizer)
bool get_lhs_equals_rhs()
void set_is_initialized(bool p_init)
virtual bool delete_optimization()
void set_cache_size(int32_t size)
float64_t kernel(int32_t idx_a, int32_t idx_b)
virtual void set_optimization_type(EOptimizationType t)
virtual void remove_rhs()
takes all necessary steps if the rhs is removed from kernel
TanimotoKernelNormalizer performs kernel normalization inspired by the Tanimoto coefficient (see http...
virtual int32_t get_num_vec_lhs()
static float64_t floor(float64_t d)
int32_t cache_size
cache_size in MB
EFeatureClass
shogun feature class
bool get_is_initialized()
float64_t combined_kernel_weight
virtual void register_params()
virtual SGVector< float64_t > get_kernel_col(int32_t j)
virtual void remove_lhs_and_rhs()
bool has_property(EKernelProperty p)
virtual CKernelNormalizer * get_normalizer()
Class SGObject is the base class of all shogun objects.
SGMatrix< float64_t > get_kernel_matrix()
virtual EFeatureType get_feature_type()=0
void set_combined_kernel_weight(float64_t nw)
KERNELCACHE_ELEM * kernel_matrix
A File access base class.
virtual void save_serializable_post()
virtual float64_t compute_optimized(int32_t vector_idx)
EOptimizationType get_optimization_type()
void unset_property(EKernelProperty p)
float64_t get_combined_kernel_weight()
The MultitaskKernel allows Multitask Learning via a modified kernel function.
virtual const float64_t * get_subkernel_weights(int32_t &num_weights)
Normalize the kernel by a constant obtained from the first element of the kernel matrix, i.e. .
Normalize the kernel by adding a constant term to its diagonal. This aids kernels to become positive ...
int32_t num_lhs
number of feature vectors on left hand side
The class Kernel Normalizer defines a function to post-process kernel values.
static bool cancel_computations()
ZeroMeanCenterKernelNormalizer centers the kernel in feature space.
virtual int32_t get_num_vec_rhs()
virtual void set_subkernel_weights(SGVector< float64_t > weights)
virtual bool init_normalizer()
bool optimization_initialized
EFeatureType
shogun feature type
EOptimizationType opt_type
CFeatures * rhs
feature vectors to occur on right hand side
Base-class for parameterized Kernel Normalizers.
SqrtDiagKernelNormalizer divides by the Square Root of the product of the diagonal elements...
virtual void compute_batch(int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *alphas, float64_t factor=1.0)
Normalize the kernel by either a constant or the average value of the diagonal elements (depending on...
virtual EKernelType get_kernel_type()=0
virtual bool init_optimization(int32_t count, int32_t *IDX, float64_t *weights)
CFeatures * lhs
feature vectors to occur on left hand side
The class Features is the base class of all feature objects.
virtual void save_serializable_pre()
static void * get_kernel_matrix_helper(void *p)
virtual void remove_lhs()
virtual int32_t get_num_subkernels()
bool init_optimization_svm(CSVM *svm)
A generic Support Vector Machine Interface.
CKernelNormalizer * normalizer
virtual SGVector< float64_t > get_kernel_row(int32_t i)
virtual float64_t normalize(float64_t value, int32_t idx_lhs, int32_t idx_rhs)=0
static float32_t sqrt(float32_t x)
x^0.5
virtual bool has_features()
virtual void add_to_normal(int32_t vector_idx, float64_t weight)
#define SG_MALLOC(type, len)
float64_t KERNELCACHE_ELEM
void set_property(EKernelProperty p)
VarianceKernelNormalizer divides by the ``variance''.
virtual EFeatureClass get_feature_class()=0