Skip to content

Commit

Permalink
Moved set/get code from .h to .cpp for DR preprocessors
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed Sep 25, 2011
1 parent 75685b6 commit a6426c4
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 67 deletions.
11 changes: 11 additions & 0 deletions src/shogun/preprocessor/Isomap.cpp
Expand Up @@ -70,6 +70,17 @@ CIsomap::~CIsomap()
{
}

void CIsomap::set_k(int32_t k)
{
ASSERT(k>0);
m_k = k;
}

int32_t CIsomap::get_k() const
{
return m_k;
}

bool CIsomap::init(CFeatures* features)
{
return true;
Expand Down
14 changes: 3 additions & 11 deletions src/shogun/preprocessor/Isomap.h
Expand Up @@ -87,22 +87,14 @@ class CIsomap: public CMultidimensionalScaling
virtual inline EPreprocessorType get_type() const { return P_ISOMAP; };

/** setter for k parameter
* @param k
* @param k value
*/
void inline set_k(int32_t k)
{
ASSERT(k>=1);
m_k = k;
}
void set_k(int32_t k);

/** getter for k parameter
* @return k value
*/
int32_t inline get_k()
{
return m_k;
}

int32_t get_k() const;

protected:

Expand Down
17 changes: 13 additions & 4 deletions src/shogun/preprocessor/LocallyLinearEmbedding.cpp
Expand Up @@ -100,22 +100,31 @@ CLocallyLinearEmbedding::CLocallyLinearEmbedding() :
CDimensionReductionPreprocessor()
{
m_k = 3;
m_posdef = true;

init();
}

void CLocallyLinearEmbedding::init()
{
m_parameters->add(&m_k, "k", "number of neighbors");
m_parameters->add(&m_posdef, "posdef",
"indicates if matrix should be considered as positive definite");
}


CLocallyLinearEmbedding::~CLocallyLinearEmbedding()
{
}

void CLocallyLinearEmbedding::set_k(int32_t k)
{
ASSERT(k>0);
m_k = k;
}

int32_t CLocallyLinearEmbedding::get_k() const
{
return m_k;
}

bool CLocallyLinearEmbedding::init(CFeatures* features)
{
return true;
Expand Down Expand Up @@ -331,7 +340,7 @@ SGMatrix<float64_t> CLocallyLinearEmbedding::find_null_space(SGMatrix<float64_t>
// using ARPACK (faster)
eigenvalues_vector = SG_MALLOC(float64_t, dimension+1);
#ifdef HAVE_ARPACK
arpack_dsaeupd_wrap(matrix.matrix,NULL,N,dimension+1,"LA",3,m_posdef,-1e-9,0.0,
arpack_dsaeupd_wrap(matrix.matrix,NULL,N,dimension+1,"LA",3,true,-1e-9,0.0,
eigenvalues_vector,matrix.matrix,eigenproblem_status);
#endif
}
Expand Down
35 changes: 5 additions & 30 deletions src/shogun/preprocessor/LocallyLinearEmbedding.h
Expand Up @@ -76,36 +76,14 @@ class CLocallyLinearEmbedding: public CDimensionReductionPreprocessor
virtual SGVector<float64_t> apply_to_feature_vector(SGVector<float64_t> vector);

/** setter for k parameter
* @param k k
* @param k k value
*/
void inline set_k(int32_t k)
{
m_k = k;
}
void set_k(int32_t k);

/** getter for k parameter
* @return k value
*/
int32_t inline get_k()
{
return m_k;
}

/** setter for posdef parameter
* @param posdef posdef value
*/
void inline set_posdef(bool posdef)
{
m_posdef = posdef;
}

/** getter for posdef parameter
* @return posdef value
*/
bool inline get_posdef()
{
return m_posdef;
}
int32_t get_k() const;

/** get name */
virtual inline const char* get_name() const { return "LocallyLinearEmbedding"; };
Expand Down Expand Up @@ -137,12 +115,10 @@ class CLocallyLinearEmbedding: public CDimensionReductionPreprocessor
/** number of neighbors */
int32_t m_k;

/** boolean indicating if matrix should be considered as positive-definite */
bool m_posdef;

public:

/** adaptive k choice */
/** adaptive k choice
* NOT IMPLEMENTED */
static const int32_t ADAPTIVE_K = -1;

protected:
Expand All @@ -162,7 +138,6 @@ class CLocallyLinearEmbedding: public CDimensionReductionPreprocessor
*/
static void* run_sparsedot_thread(void* p);


};
}

Expand Down
29 changes: 29 additions & 0 deletions src/shogun/preprocessor/MultidimensionalScaling.cpp
Expand Up @@ -68,6 +68,7 @@ CMultidimensionalScaling::CMultidimensionalScaling() : CDimensionReductionPrepro

void CMultidimensionalScaling::init()
{
m_parameters->add(&m_eigenvalues, "eigenvalues", "eigenvalues of last embedding");
m_parameters->add(&m_landmark, "landmark", "indicates if landmark approximation should be used");
m_parameters->add(&m_landmark_number, "landmark number", "the number of landmarks for approximation");
}
Expand All @@ -86,6 +87,34 @@ CMultidimensionalScaling::~CMultidimensionalScaling()
m_eigenvalues.destroy_vector();
}

SGVector<float64_t> CMultidimensionalScaling::get_eigenvalues() const
{
return m_eigenvalues;
}

void CMultidimensionalScaling::set_landmark_number(int32_t num)
{
if (num<3)
SG_ERROR("Number of landmarks should be greater than 3 to make triangulation possible while %d given.",
num);
m_landmark_number = num;
}

int32_t CMultidimensionalScaling::get_landmark_number() const
{
return m_landmark_number;
}

void CMultidimensionalScaling::set_landmark(bool landmark)
{
m_landmark = landmark;
}

bool CMultidimensionalScaling::get_landmark() const
{
return m_landmark;
}

CSimpleFeatures<float64_t>* CMultidimensionalScaling::apply_to_distance(CDistance* distance)
{
ASSERT(distance);
Expand Down
27 changes: 5 additions & 22 deletions src/shogun/preprocessor/MultidimensionalScaling.h
Expand Up @@ -103,46 +103,29 @@ class CMultidimensionalScaling: public CDimensionReductionPreprocessor
/** get last embedding eigenvectors
* @return vector with last eigenvalues
*/
SGVector<float64_t> get_eigenvalues() const
{
return m_eigenvalues;
}
SGVector<float64_t> get_eigenvalues() const;

/** set number of landmarks
* should be lesser than number of examples and greater than 3
* for consistent embedding as triangulation is used
* @param num number of landmark to be set
*/
void set_landmark_number(int32_t num)
{
if (num<3)
SG_ERROR("Landmark number should be greater than 3 (%d given).", num);
m_landmark_number = num;
};
void set_landmark_number(int32_t num);

/** get number of landmarks
* @return current number of landmarks
*/
int32_t get_landmark_number() const
{
return m_landmark_number;
};
int32_t get_landmark_number() const;

/** setter for landmark parameter
* @param landmark true if landmark embedding should be used
*/
void set_landmark(bool landmark)
{
m_landmark = landmark;
};
void set_landmark(bool landmark);

/** getter for landmark parameter
* @return true if landmark embedding is used
*/
bool get_landmark() const
{
return m_landmark;
};
bool get_landmark() const;

protected:

Expand Down

0 comments on commit a6426c4

Please sign in to comment.