Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
-added create_centering_matrix which returns a matrix that can be used
to center data matrices
  • Loading branch information
karlnapf committed Jun 3, 2012
1 parent 71ddf75 commit be0a1f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/shogun/mathematics/Math.cpp
Expand Up @@ -305,6 +305,20 @@ SGMatrix<int32_t> CMath::create_identity_matrix(index_t size, int32_t scale)
return I;
}

template <>
SGMatrix<float64_t> CMath::create_centering_matrix(index_t size)
{
SGMatrix<float64_t> H=CMath::create_identity_matrix(size, 1.0);

float64_t subtract=1.0/size;
for (index_t i=0; i<size; ++i)
{
for (index_t j=0; j<0; ++j)
H(i,j)-=subtract;
}

return H;
}
}

SGVector<float64_t> CMath::fishers_exact_test_for_multiple_2x3_tables(SGMatrix<float64_t> tables)
Expand Down
16 changes: 15 additions & 1 deletion src/shogun/mathematics/Math.h
Expand Up @@ -495,12 +495,26 @@ class CMath : public CSGObject

/** returns the identity matrix, scaled by a factor
*
* @param size size of square idenity matrix
* @param size size of square identity matrix
* @param scale (optional) scaling factor
*/
template <class T>
static SGMatrix<T> create_identity_matrix(index_t size, T scale);

/** returns the centering matrix, given by H=I-1/n*O, where
* I is the identity matrix, O is a square matrix of ones of size n
* Multiplied from the left hand side, subtracts from each column
* its mean.
* Multiplied from the right hand side, subtracts from each row
* its mean (so from each dimension of a SHOGUN feature)
*
* Note that H*H=H=H^T
*
* @param size size of centering matrix
*/
template <class T>
static SGMatrix<T> create_centering_matrix(index_t size);

#ifdef HAVE_LAPACK
/** compute eigenvalues and eigenvectors of symmetric matrix using
* LAPACK
Expand Down

0 comments on commit be0a1f5

Please sign in to comment.