The Combined kernel is used to combine a number of kernels into a single CombinedKernel object by linear combination.
It keeps pointers to the added sub-kernels and for each sub-kernel - a kernel specific weight
.
It is especially useful to combine kernels working on different domains and to combine kernels looking at independent features and requires CCombinedFeatures to be used.
It is defined as:
Definition at line 40 of file CombinedKernel.h.
Public Member Functions | |
CCombinedKernel (int32_t size=10, bool append_subkernel_weights=false) | |
virtual | ~CCombinedKernel () |
virtual bool | init (CFeatures *lhs, CFeatures *rhs) |
virtual void | cleanup () |
virtual bool | load_init (FILE *src) |
virtual bool | save_init (FILE *dest) |
virtual EKernelType | get_kernel_type () |
virtual EFeatureType | get_feature_type () |
virtual EFeatureClass | get_feature_class () |
virtual const char * | get_name () const |
void | list_kernels () |
CKernel * | get_first_kernel () |
CKernel * | get_first_kernel (CListElement< CKernel * > *¤t) |
CKernel * | get_kernel (int32_t idx) |
CKernel * | get_last_kernel () |
CKernel * | get_next_kernel () |
CKernel * | get_next_kernel (CListElement< CKernel * > *¤t) |
bool | insert_kernel (CKernel *k) |
bool | append_kernel (CKernel *k) |
bool | delete_kernel () |
bool | get_append_subkernel_weights () |
int32_t | get_num_subkernels () |
virtual int32_t | get_num_vec_lhs () |
virtual int32_t | get_num_vec_rhs () |
virtual bool | has_features () |
virtual void | remove_lhs () |
virtual void | remove_rhs () |
virtual void | remove_lhs_and_rhs () |
virtual bool | init_optimization (int32_t count, int32_t *IDX, float64_t *weights) |
virtual bool | delete_optimization () |
virtual float64_t | compute_optimized (int32_t idx) |
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) |
void | emulate_compute_batch (CKernel *k, int32_t num_vec, int32_t *vec_idx, float64_t *target, int32_t num_suppvec, int32_t *IDX, float64_t *weights) |
virtual void | add_to_normal (int32_t idx, float64_t weight) |
virtual void | clear_normal () |
virtual void | compute_by_subkernel (int32_t idx, float64_t *subkernel_contrib) |
virtual const float64_t * | get_subkernel_weights (int32_t &num_weights) |
virtual void | get_subkernel_weights (float64_t **weights, int32_t *num_weights) |
virtual void | set_subkernel_weights (float64_t *weights, int32_t num_weights) |
virtual void | set_optimization_type (EOptimizationType t) |
bool | precompute_subkernels () |
Static Public Member Functions | |
static void * | compute_optimized_kernel_helper (void *p) |
static void * | compute_kernel_helper (void *p) |
Protected Member Functions | |
virtual float64_t | compute (int32_t x, int32_t y) |
void | adjust_num_lhs_rhs_initialized (CKernel *k) |
Protected Attributes | |
CList< CKernel * > * | kernel_list |
int32_t | sv_count |
int32_t * | sv_idx |
float64_t * | sv_weight |
float64_t * | subkernel_weights_buffer |
bool | append_subkernel_weights |
int32_t | num_lhs |
int32_t | num_rhs |
bool | initialized |
CCombinedKernel::CCombinedKernel | ( | int32_t | size = 10 , |
|
bool | append_subkernel_weights = false | |||
) |
constructor
size | cache size | |
append_subkernel_weights | if subkernel weights shall be appended |
Definition at line 43 of file CombinedKernel.cpp.
CCombinedKernel::~CCombinedKernel | ( | ) | [virtual] |
Definition at line 55 of file CombinedKernel.cpp.
void CCombinedKernel::add_to_normal | ( | int32_t | idx, | |
float64_t | weight | |||
) | [virtual] |
add to normal vector
idx | where to add | |
weight | what to add |
Reimplemented from CKernel.
Definition at line 584 of file CombinedKernel.cpp.
void CCombinedKernel::adjust_num_lhs_rhs_initialized | ( | CKernel * | k | ) | [protected] |
adjust the variables num_lhs, num_rhs and initialized bast on the kernel to be appended/inserted
k | kernel |
Definition at line 424 of file CombinedKernel.h.
bool CCombinedKernel::append_kernel | ( | CKernel * | k | ) |
append kernel
k | kernel |
Definition at line 202 of file CombinedKernel.h.
void CCombinedKernel::cleanup | ( | ) | [virtual] |
void CCombinedKernel::clear_normal | ( | ) | [virtual] |
float64_t CCombinedKernel::compute | ( | int32_t | x, | |
int32_t | y | |||
) | [protected, virtual] |
compute kernel function
x | x | |
y | y |
Implements CKernel.
Definition at line 248 of file CombinedKernel.cpp.
void CCombinedKernel::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 | |||
) | [virtual] |
computes output for a batch of examples in an optimized fashion (favorable if kernel supports it, i.e. has KP_BATCHEVALUATION. to the outputvector target (of length num_vec elements) the output for the examples enumerated in vec_idx are added. therefore make sure that it is initialized with ZERO. the following num_suppvec, IDX, alphas arguments are the number of support vectors, their indices and weights
Reimplemented from CKernel.
Definition at line 341 of file CombinedKernel.cpp.
void CCombinedKernel::compute_by_subkernel | ( | int32_t | idx, | |
float64_t * | subkernel_contrib | |||
) | [virtual] |
compute by subkernel
idx | index | |
subkernel_contrib | subkernel contribution |
Reimplemented from CKernel.
Definition at line 612 of file CombinedKernel.cpp.
void * CCombinedKernel::compute_kernel_helper | ( | void * | p | ) | [static] |
helper for compute kernel
p | thread parameter |
Definition at line 388 of file CombinedKernel.cpp.
float64_t CCombinedKernel::compute_optimized | ( | int32_t | idx | ) | [virtual] |
compute optimized
idx | index to compute |
Reimplemented from CKernel.
Definition at line 539 of file CombinedKernel.cpp.
void * CCombinedKernel::compute_optimized_kernel_helper | ( | void * | p | ) | [static] |
helper for compute optimized kernel
p | thread parameter |
Definition at line 375 of file CombinedKernel.cpp.
bool CCombinedKernel::delete_kernel | ( | ) |
bool CCombinedKernel::delete_optimization | ( | ) | [virtual] |
delete optimization
Reimplemented from CKernel.
Definition at line 315 of file CombinedKernel.cpp.
void CCombinedKernel::emulate_compute_batch | ( | CKernel * | k, | |
int32_t | num_vec, | |||
int32_t * | vec_idx, | |||
float64_t * | target, | |||
int32_t | num_suppvec, | |||
int32_t * | IDX, | |||
float64_t * | weights | |||
) |
emulates batch computation, via linadd optimization w^t x or even down to sum_i alpha_i K(x_i,x)
k | kernel | |
num_vec | number of vectors | |
vec_idx | vector index | |
target | target | |
num_suppvec | number of support vectors | |
IDX | IDX | |
weights | weights |
Definition at line 410 of file CombinedKernel.cpp.
bool CCombinedKernel::get_append_subkernel_weights | ( | ) |
check if subkernel weights are appended
Definition at line 236 of file CombinedKernel.h.
virtual EFeatureClass CCombinedKernel::get_feature_class | ( | ) | [virtual] |
return feature class the kernel can deal with
Implements CKernel.
Definition at line 104 of file CombinedKernel.h.
virtual EFeatureType CCombinedKernel::get_feature_type | ( | ) | [virtual] |
return feature type the kernel can deal with
Implements CKernel.
Definition at line 95 of file CombinedKernel.h.
CKernel* CCombinedKernel::get_first_kernel | ( | CListElement< CKernel * > *& | current | ) |
get first kernel
current |
Definition at line 132 of file CombinedKernel.h.
CKernel* CCombinedKernel::get_first_kernel | ( | ) |
CKernel* CCombinedKernel::get_kernel | ( | int32_t | idx | ) |
get kernel
idx | index of kernel |
Definition at line 142 of file CombinedKernel.h.
virtual EKernelType CCombinedKernel::get_kernel_type | ( | ) | [virtual] |
return what type of kernel we are
Implements CKernel.
Definition at line 86 of file CombinedKernel.h.
CKernel* CCombinedKernel::get_last_kernel | ( | ) |
virtual const char* CCombinedKernel::get_name | ( | ) | const [virtual] |
return the kernel's name
Implements CSGObject.
Definition at line 113 of file CombinedKernel.h.
CKernel* CCombinedKernel::get_next_kernel | ( | CListElement< CKernel * > *& | current | ) |
get next kernel multi-thread safe
current |
Definition at line 176 of file CombinedKernel.h.
CKernel* CCombinedKernel::get_next_kernel | ( | ) |
int32_t CCombinedKernel::get_num_subkernels | ( | ) | [virtual] |
get number of subkernels
Reimplemented from CKernel.
Definition at line 245 of file CombinedKernel.h.
virtual int32_t CCombinedKernel::get_num_vec_lhs | ( | ) | [virtual] |
get number of vectors of lhs features
Reimplemented from CKernel.
Definition at line 269 of file CombinedKernel.h.
virtual int32_t CCombinedKernel::get_num_vec_rhs | ( | ) | [virtual] |
get number of vectors of rhs features
Reimplemented from CKernel.
Definition at line 278 of file CombinedKernel.h.
void CCombinedKernel::get_subkernel_weights | ( | float64_t ** | weights, | |
int32_t * | num_weights | |||
) | [virtual] |
get subkernel weights (swig compatible)
weights | subkernel weights | |
num_weights | number of weights |
Definition at line 693 of file CombinedKernel.cpp.
const float64_t * CCombinedKernel::get_subkernel_weights | ( | int32_t & | num_weights | ) | [virtual] |
get subkernel weights
num_weights | where number of weights is stored |
Reimplemented from CKernel.
Definition at line 651 of file CombinedKernel.cpp.
virtual bool CCombinedKernel::has_features | ( | ) | [virtual] |
test whether features have been assigned to lhs and rhs
Reimplemented from CKernel.
Definition at line 287 of file CombinedKernel.h.
initialize kernel
lhs | features of left-hand side | |
rhs | features of right-hand side |
Reimplemented from CKernel.
Definition at line 66 of file CombinedKernel.cpp.
bool CCombinedKernel::init_optimization | ( | int32_t | count, | |
int32_t * | IDX, | |||
float64_t * | weights | |||
) | [virtual] |
initialize optimization
count | count | |
IDX | index | |
weights | weights |
Reimplemented from CKernel.
Definition at line 264 of file CombinedKernel.cpp.
bool CCombinedKernel::insert_kernel | ( | CKernel * | k | ) |
insert kernel
k | kernel |
Definition at line 186 of file CombinedKernel.h.
void CCombinedKernel::list_kernels | ( | ) |
list kernels
Definition at line 230 of file CombinedKernel.cpp.
virtual bool CCombinedKernel::load_init | ( | FILE * | src | ) | [virtual] |
load kernel init_data
NOT IMPLEMENTED!
src | file to load from |
Implements CKernel.
Definition at line 71 of file CombinedKernel.h.
bool CCombinedKernel::precompute_subkernels | ( | ) |
precompute all sub-kernels
Definition at line 753 of file CombinedKernel.cpp.
void CCombinedKernel::remove_lhs | ( | ) | [virtual] |
remove lhs from kernel
Reimplemented from CKernel.
Definition at line 152 of file CombinedKernel.cpp.
void CCombinedKernel::remove_lhs_and_rhs | ( | ) | [virtual] |
remove lhs and rhs from kernel
Reimplemented from CKernel.
Definition at line 189 of file CombinedKernel.cpp.
void CCombinedKernel::remove_rhs | ( | ) | [virtual] |
remove rhs from kernel
Reimplemented from CKernel.
Definition at line 172 of file CombinedKernel.cpp.
virtual bool CCombinedKernel::save_init | ( | FILE * | dest | ) | [virtual] |
save kernel init_data
NOT IMPLEMENTED!
dest | file to save to |
Implements CKernel.
Definition at line 80 of file CombinedKernel.h.
void CCombinedKernel::set_optimization_type | ( | EOptimizationType | t | ) | [virtual] |
set optimization type
t | optimization type |
Reimplemented from CKernel.
Definition at line 738 of file CombinedKernel.cpp.
void CCombinedKernel::set_subkernel_weights | ( | float64_t * | weights, | |
int32_t | num_weights | |||
) | [virtual] |
set subkernel weights
weights | new subkernel weights | |
num_weights | number of subkernel weights |
Reimplemented from CKernel.
Definition at line 704 of file CombinedKernel.cpp.
bool CCombinedKernel::append_subkernel_weights [protected] |
if subkernel weights are appended
Definition at line 471 of file CombinedKernel.h.
bool CCombinedKernel::initialized [protected] |
whether kernel is ready to be used
Definition at line 477 of file CombinedKernel.h.
CList<CKernel*>* CCombinedKernel::kernel_list [protected] |
list of kernels
Definition at line 461 of file CombinedKernel.h.
int32_t CCombinedKernel::num_lhs [protected] |
number of vectors on lhs
Definition at line 473 of file CombinedKernel.h.
int32_t CCombinedKernel::num_rhs [protected] |
number of vectors on lhs
Definition at line 475 of file CombinedKernel.h.
float64_t* CCombinedKernel::subkernel_weights_buffer [protected] |
subkernel weights buffers
Definition at line 469 of file CombinedKernel.h.
int32_t CCombinedKernel::sv_count [protected] |
support vector count
Definition at line 463 of file CombinedKernel.h.
int32_t* CCombinedKernel::sv_idx [protected] |
support vector index
Definition at line 465 of file CombinedKernel.h.
float64_t* CCombinedKernel::sv_weight [protected] |
support vector weights
Definition at line 467 of file CombinedKernel.h.