Skip to content

Commit

Permalink
fixed set_triangle_kernel_matrix_from_full in custom kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
gsomix committed Apr 8, 2012
1 parent 46353c3 commit c5c7117
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 4 additions & 4 deletions examples/undocumented/python_modular/kernel_custom_modular.py
@@ -1,9 +1,9 @@
from numpy.random import seed
seed(42)

parameter_list=[[7],[8]]
parameter_list=[[3],[3]]

def kernel_custom_modular (dim=7):
def kernel_custom_modular (dim=1):
from numpy.random import rand, seed
from numpy import array, float32
from shogun.Features import RealFeatures
Expand All @@ -25,7 +25,7 @@ def kernel_custom_modular (dim=7):
kernel.set_triangle_kernel_matrix_from_full(symdata)
km_fulltriangle=kernel.get_kernel_matrix()

kernel.set_full_kernel_matrix_from_full(data)
kernel.set_full_kernel_matrix_from_full(symdata)
km_fullfull=kernel.get_kernel_matrix()

# now once with float32's
Expand All @@ -37,7 +37,7 @@ def kernel_custom_modular (dim=7):
kernel.set_triangle_kernel_matrix_from_full(symdata)
km_fulltriangle=kernel.get_kernel_matrix()

kernel.set_full_kernel_matrix_from_full(data)
kernel.set_full_kernel_matrix_from_full(symdata)
km_fullfull=kernel.get_kernel_matrix()
return km_fullfull,kernel

Expand Down
3 changes: 1 addition & 2 deletions src/shogun/kernel/CustomKernel.cpp
Expand Up @@ -185,8 +185,7 @@ void CCustomKernel::print_kernel_matrix(const char* prefix) const
{
index_t real_i=row_subset_idx_conversion(i);
index_t real_j=col_subset_idx_conversion(j);
SG_PRINT("%s%4.2f", kmatrix.matrix[kmatrix.num_rows*real_j+real_i],
prefix);
SG_PRINT("%s%4.2f", prefix, kmatrix.matrix[kmatrix.num_rows*real_j+real_i]);
if (j<num_cols-1)
SG_PRINT(", \t");
}
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/kernel/CustomKernel.h
Expand Up @@ -216,10 +216,10 @@ class CCustomKernel: public CKernel
cleanup_custom();
SG_DEBUG( "using custom kernel of size %dx%d\n", cols,cols);

kmatrix.matrix = SG_MALLOC(float32_t, int64_t(rows)*cols);
kmatrix.matrix = SG_MALLOC(float32_t, cols*(cols+1)/2);
kmatrix.num_rows = rows;
kmatrix.num_cols = cols;
upper_diagonal = false;
kmatrix.num_cols = cols;
upper_diagonal = true;

for (int64_t row=0; row<rows; row++)
{
Expand Down

0 comments on commit c5c7117

Please sign in to comment.