Skip to content

Commit

Permalink
Improvements for difmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Jan 26, 2012
1 parent 73a2d9b commit 9162f9f
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/shogun/converter/DiffusionMaps.cpp
Expand Up @@ -15,6 +15,7 @@
#include <shogun/mathematics/arpack.h>
#include <shogun/mathematics/lapack.h>
#include <shogun/mathematics/Math.h>
#include <shogun/kernel/GaussianKernel.h>
#include <shogun/io/SGIO.h>
#include <shogun/kernel/Kernel.h>
#include <shogun/lib/Signal.h>
Expand All @@ -26,6 +27,7 @@ CDiffusionMaps::CDiffusionMaps() :
CEmbeddingConverter()
{
m_t = 10;
set_kernel(new CGaussianKernel(10,1.0));

init();
}
Expand Down Expand Up @@ -88,14 +90,15 @@ CSimpleFeatures<float64_t>* CDiffusionMaps::embed_kernel(CKernel* kernel)
p_vector[i] += kernel_matrix.matrix[j*N+i];
}
}

float64_t* p_matrix = SG_CALLOC(float64_t, N*N);
cblas_dger(CblasColMajor,N,N,1.0,p_vector,1,p_vector,1,p_matrix,N);
for (i=0; i<N*N; i++)
//CMath::display_matrix(kernel_matrix.matrix,N,N,"K");
for (i=0; i<N; i++)
{
kernel_matrix.matrix[i] /= CMath::pow(p_matrix[i], m_t);
for (j=0; j<N; j++)
{
kernel_matrix.matrix[i*N+j] /= CMath::pow(p_vector[i]*p_vector[j], m_t);
}
}
SG_FREE(p_matrix);
//CMath::display_matrix(kernel_matrix.matrix,N,N,"K");

for (i=0; i<N; i++)
{
Expand All @@ -106,12 +109,16 @@ CSimpleFeatures<float64_t>* CDiffusionMaps::embed_kernel(CKernel* kernel)
}
p_vector[i] = CMath::sqrt(p_vector[i]);
}
float64_t ppt = cblas_ddot(N,p_vector,1,p_vector,1);
SG_FREE(p_vector);

for (i=0; i<N*N; i++)
kernel_matrix.matrix[i] /= ppt;
for (i=0; i<N; i++)
{
for (j=0; j<N; j++)
{
kernel_matrix.matrix[i*N+j] /= p_vector[i]*p_vector[j];
}
}

SG_FREE(p_vector);
float64_t* s_values = SG_MALLOC(float64_t, N);

int32_t info = 0;
Expand All @@ -122,7 +129,7 @@ CSimpleFeatures<float64_t>* CDiffusionMaps::embed_kernel(CKernel* kernel)
#ifdef HAVE_ARPACK
arpack_dsxupd(kernel_matrix.matrix,NULL,false,N,m_target_dim,"LA",false,1,false,true,0.0,0.0,s_values,kernel_matrix.matrix,info);
#endif /* HAVE_ARPACK */
SG_REALLOC(float64_t,kernel_matrix.matrix,m_target_dim*N);
SG_REALLOC(float64_t,kernel_matrix.matrix,N*m_target_dim);
new_feature_matrix = SGMatrix<float64_t>(kernel_matrix.matrix,m_target_dim,N);
}
else
Expand All @@ -139,10 +146,7 @@ CSimpleFeatures<float64_t>* CDiffusionMaps::embed_kernel(CKernel* kernel)
kernel_matrix.destroy_matrix();
}
if (info)
{
SG_ERROR("Eigenproblem solving failed with %d code", info);
kernel_matrix.destroy_matrix();
}

SG_FREE(s_values);

Expand Down

0 comments on commit 9162f9f

Please sign in to comment.