Skip to content

Commit

Permalink
Some necessary improvements from the reverted commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Oct 2, 2011
1 parent 15ebd97 commit 9698ed3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 33 deletions.
3 changes: 1 addition & 2 deletions src/shogun/preprocessor/Isomap.cpp
Expand Up @@ -202,7 +202,7 @@ SGMatrix<float64_t> CIsomap::isomap_distance(SGMatrix<float64_t> D_matrix)
heaps[t] = new CFibonacciHeap(N);

#else
int32_t num_threads = 1;
int32_t num_threads = 1;
#endif

// allocate (s)olution
Expand Down Expand Up @@ -251,7 +251,6 @@ SGMatrix<float64_t> CIsomap::isomap_distance(SGMatrix<float64_t> D_matrix)
single_thread_param.s = s;
single_thread_param.f = f;
single_thread_param.shortest_D = shortest_D;

run_dijkstra_thread((void*)&single_thread_param);
delete single_thread_param.heap;
#endif
Expand Down
29 changes: 5 additions & 24 deletions src/shogun/preprocessor/KernelLocallyLinearEmbedding.cpp
Expand Up @@ -136,7 +136,7 @@ SGMatrix<float64_t> CKernelLocallyLinearEmbedding::apply_to_feature_matrix(CFeat
// get dimensionality and number of vectors of data
bool is_simple = ((features->get_feature_class()==C_SIMPLE) && (features->get_feature_type()==F_DREAL));
int32_t N = features->get_num_vectors();
int32_t target_dim;
int32_t target_dim = 0;
if (is_simple)
target_dim = calculate_effective_target_dim(((CSimpleFeatures<float64_t>*)features)->get_num_features());
else
Expand All @@ -158,7 +158,7 @@ SGMatrix<float64_t> CKernelLocallyLinearEmbedding::apply_to_feature_matrix(CFeat
m_kernel->cleanup();

// init W (weight) matrix
SGMatrix<float64_t> M_matrix = construct_weight_matrix(kernel_matrix,neighborhood_matrix);
SGMatrix<float64_t> M_matrix = construct_weight_matrix(kernel_matrix,neighborhood_matrix,target_dim);
neighborhood_matrix.destroy_matrix();

SGMatrix<float64_t> nullspace = find_null_space(M_matrix,target_dim);
Expand All @@ -179,7 +179,8 @@ SGMatrix<float64_t> CKernelLocallyLinearEmbedding::apply_to_feature_matrix(CFeat
}

SGMatrix<float64_t> CKernelLocallyLinearEmbedding::construct_weight_matrix(SGMatrix<float64_t> kernel_matrix,
SGMatrix<int32_t> neighborhood_matrix)
SGMatrix<int32_t> neighborhood_matrix,
int32_t target_dim)
{
int32_t N = kernel_matrix.num_cols;
// loop variables
Expand Down Expand Up @@ -317,22 +318,6 @@ SGVector<float64_t> CKernelLocallyLinearEmbedding::apply_to_feature_vector(SGVec
return vector;
}

void CKernelLocallyLinearEmbedding::construct_local_gram_matrix(float64_t* local_gram_matrix,
const float64_t* kernel_matrix,
const int32_t* neighborhood_matrix,
int32_t i, int32_t N, int32_t m_k_)
{
for (int32_t j=0; j<m_k_; j++)
{
for (int32_t k=0; k<m_k_; k++)
local_gram_matrix[j*m_k_+k] =
kernel_matrix[i*N+i] -
kernel_matrix[i*N+neighborhood_matrix[j*N+i]] -
kernel_matrix[i*N+neighborhood_matrix[k*N+i]] +
kernel_matrix[neighborhood_matrix[j*N+i]*N+neighborhood_matrix[k*N+i]];
}
}

void* CKernelLocallyLinearEmbedding::run_linearreconstruction_thread(void* p)
{
LK_RECONSTRUCTION_THREAD_PARAM* parameters = (LK_RECONSTRUCTION_THREAD_PARAM*)p;
Expand All @@ -347,14 +332,11 @@ void* CKernelLocallyLinearEmbedding::run_linearreconstruction_thread(void* p)
float64_t* id_vector = parameters->id_vector;
float64_t* W_matrix = parameters->W_matrix;

int32_t i,j;
int32_t i,j,k;
float64_t norming,trace;

for (i=idx_start; i<idx_stop; i+=idx_step)
{
// form local gram matrix
construct_local_gram_matrix(local_gram_matrix,kernel_matrix,neighborhood_matrix,i,N,m_k);
/*
for (j=0; j<m_k; j++)
{
for (k=0; k<m_k; k++)
Expand All @@ -364,7 +346,6 @@ void* CKernelLocallyLinearEmbedding::run_linearreconstruction_thread(void* p)
kernel_matrix[i*N+neighborhood_matrix[k*N+i]] +
kernel_matrix[neighborhood_matrix[j*N+i]*N+neighborhood_matrix[k*N+i]];
}
*/

for (j=0; j<m_k; j++)
id_vector[j] = 1.0;
Expand Down
7 changes: 2 additions & 5 deletions src/shogun/preprocessor/KernelLocallyLinearEmbedding.h
Expand Up @@ -79,11 +79,8 @@ class CKernelLocallyLinearEmbedding: public CLocallyLinearEmbedding

/** construct weight matrix */
virtual SGMatrix<float64_t> construct_weight_matrix(SGMatrix<float64_t> kernel_matrix,
SGMatrix<int32_t> neighborhood_matrix);

/** construct local gram matrix */
static void construct_local_gram_matrix(float64_t* local_gram_matrix, const float64_t* kernel_matrix,
const int32_t* neighborhood_matrix, int32_t i, int32_t N, int32_t m_k_);
SGMatrix<int32_t> neighborhood_matrix,
int32_t target_dim);

/** runs neighborhood determination thread
* @param p thread params
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/preprocessor/LocallyLinearEmbedding.cpp
Expand Up @@ -161,7 +161,7 @@ SGMatrix<float64_t> CLocallyLinearEmbedding::apply_to_feature_matrix(CFeatures*
int32_t dim = simple_features->get_num_features();
int32_t target_dim = calculate_effective_target_dim(dim);
if (target_dim==-1)
SG_ERROR("Trying to decrease dimensionality to negative value, not possible.\n");
SG_ERROR("Trying to decrease dimensionality to non-positive value, not possible.\n");
if (target_dim>dim)
SG_ERROR("Cannot increase dimensionality: target dimensionality is %d while given features dimensionality is %d.\n",
target_dim, dim);
Expand Down Expand Up @@ -222,7 +222,7 @@ SGMatrix<float64_t> CLocallyLinearEmbedding::construct_weight_matrix(CSimpleFeat
#else
int32_t num_threads = 1;
#endif
// init matrices and norm factor to be used
// init storages to be used
float64_t* z_matrix = SG_MALLOC(float64_t, m_k*dim*num_threads);
float64_t* covariance_matrix = SG_MALLOC(float64_t, m_k*m_k*num_threads);
float64_t* id_vector = SG_MALLOC(float64_t, m_k*num_threads);
Expand Down

0 comments on commit 9698ed3

Please sign in to comment.