Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #552 from pluskid/multiclass
Fix missing doc warnings and correct some label types in MC Strategies.
  • Loading branch information
Soeren Sonnenburg committed May 25, 2012
2 parents 37f1841 + 93b9050 commit 6c4cdd5
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 22 deletions.
Expand Up @@ -15,7 +15,7 @@ def classifier_multiclassmachine_modular (fm_train_real=traindat,fm_test_real=te

labels=MulticlassLabels(label_train_multiclass)

classifier = LibSVM(C, kernel, labels)
classifier = LibSVM()
classifier.set_epsilon(epsilon)
print labels.get_labels()
mc_classifier = KernelMulticlassMachine(MulticlassOneVsRestStrategy(),kernel,classifier,labels)
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/machine/MulticlassMachine.cpp
Expand Up @@ -149,7 +149,7 @@ bool CMulticlassMachine::train_machine(CFeatures* data)
SG_REF(train_labels);
m_machine->set_labels(train_labels);

m_multiclass_strategy->train_start(m_labels, train_labels);
m_multiclass_strategy->train_start(CMulticlassLabels::obtain_from_generic(m_labels), train_labels);
while (m_multiclass_strategy->train_has_more())
{
SGVector<index_t> subset=m_multiclass_strategy->train_prepare_next();
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/multiclass/MulticlassOneVsOneStrategy.cpp
Expand Up @@ -19,7 +19,7 @@ CMulticlassOneVsOneStrategy::CMulticlassOneVsOneStrategy()
{
}

void CMulticlassOneVsOneStrategy::train_start(CLabels *orig_labels, CLabels *train_labels)
void CMulticlassOneVsOneStrategy::train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)
{
CMulticlassStrategy::train_start(orig_labels, train_labels);
m_num_machines=m_num_classes*(m_num_classes-1)/2;
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/multiclass/MulticlassOneVsOneStrategy.h
Expand Up @@ -23,7 +23,7 @@ class CMulticlassOneVsOneStrategy: public CMulticlassStrategy
virtual ~CMulticlassOneVsOneStrategy() {}

/** start training */
virtual void train_start(CLabels *orig_labels, CLabels *train_labels);
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels);

/** has more training phase */
virtual bool train_has_more();
Expand Down Expand Up @@ -52,9 +52,9 @@ class CMulticlassOneVsOneStrategy: public CMulticlassStrategy
};

protected:
int32_t m_num_machines;
int32_t m_train_pair_idx_1;
int32_t m_train_pair_idx_2;
int32_t m_num_machines; ///< number of machines
int32_t m_train_pair_idx_1; ///< 1st index of current submachine being trained
int32_t m_train_pair_idx_2; ///< 2nd index of current submachine being trained
};

} // namespace shogun
4 changes: 2 additions & 2 deletions src/shogun/multiclass/MulticlassOneVsRestStrategy.h
Expand Up @@ -46,7 +46,7 @@ class CMulticlassOneVsRestStrategy: public CMulticlassStrategy
}

/** start training */
virtual void train_start(CLabels *orig_labels, CLabels *train_labels)
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)
{
CMulticlassStrategy::train_start(orig_labels, train_labels);
}
Expand Down Expand Up @@ -81,7 +81,7 @@ class CMulticlassOneVsRestStrategy: public CMulticlassStrategy
};

protected:
CRejectionStrategy *m_rejection_strategy;
CRejectionStrategy *m_rejection_strategy; ///< rejection strategy
};

} // namespace shogun
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/multiclass/MulticlassStrategy.cpp
Expand Up @@ -20,7 +20,7 @@ CMulticlassStrategy::CMulticlassStrategy()
SG_ADD(&m_num_classes, "num_classes", "Number of classes", MS_NOT_AVAILABLE);
}

void CMulticlassStrategy::train_start(CLabels *orig_labels, CLabels *train_labels)
void CMulticlassStrategy::train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)
{
if (m_train_labels != NULL)
SG_ERROR("Stop the previous training task before starting a new one!");
Expand Down
13 changes: 7 additions & 6 deletions src/shogun/multiclass/MulticlassStrategy.h
Expand Up @@ -12,7 +12,8 @@
#define MULTICLASSSTRATEGY_H__

#include <shogun/base/SGObject.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/MulticlassLabels.h>
#include <shogun/multiclass/RejectionStrategy.h>

namespace shogun
Expand Down Expand Up @@ -46,7 +47,7 @@ class CMulticlassStrategy: public CSGObject
}

/** start training */
virtual void train_start(CLabels *orig_labels, CLabels *train_labels);
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels);

/** has more training phase */
virtual bool train_has_more()=0;
Expand All @@ -69,10 +70,10 @@ class CMulticlassStrategy: public CSGObject
virtual int32_t get_num_machines()=0;

protected:
CLabels *m_train_labels;
CLabels *m_orig_labels;
int32_t m_train_iter;
int32_t m_num_classes;
CBinaryLabels *m_train_labels; ///< labels used to train the submachines
CMulticlassLabels *m_orig_labels; ///< original multiclass labels
int32_t m_train_iter; ///< index of current iterations
int32_t m_num_classes; ///< number of classes in this problem
};

} // namespace shogun
Expand Down
5 changes: 5 additions & 0 deletions src/shogun/multiclass/ecoc/ECOCDecoder.h
Expand Up @@ -18,6 +18,11 @@
namespace shogun
{

/** An ECOC decoder describe how to decode the
* classification results of the binary classifiers
* into a multiclass label according to the ECOC
* codebook.
*/
class CECOCDecoder: public CSGObject
{
public:
Expand Down
4 changes: 3 additions & 1 deletion src/shogun/multiclass/ecoc/ECOCDiscriminantEncoder.h
Expand Up @@ -63,9 +63,10 @@ class CECOCDiscriminantEncoder: public CECOCEncoder
virtual SGMatrix<int32_t> create_codebook(int32_t num_classes);

protected:
/** init parameters */
void init();


#ifndef DOXYGEN_SHOULD_SKIP_THIS
void binary_partition(const std::vector<int32_t>& classes);
void run_sffs(std::vector<int32_t>& part1, std::vector<int32_t>& part2);
float64_t sffs_iteration(float64_t MI, std::vector<int32_t>& part1, std::set<int32_t>& idata1,
Expand All @@ -82,6 +83,7 @@ class CECOCDiscriminantEncoder: public CECOCEncoder
CLabels *m_labels;
CDenseFeatures<float64_t> *m_features;
SGMatrix<float64_t> m_feats;
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
};

} /* shogun */
Expand Down
9 changes: 6 additions & 3 deletions src/shogun/multiclass/ecoc/ECOCRandomDenseEncoder.h
Expand Up @@ -16,6 +16,9 @@
namespace shogun
{

/** Generate random ECOC codebook containing +1 and -1, and
* select the best one.
*/
class CECOCRandomDenseEncoder: public CECOCEncoder
{
public:
Expand Down Expand Up @@ -60,9 +63,9 @@ class CECOCRandomDenseEncoder: public CECOCEncoder
}

protected:
int32_t m_maxiter; // max number of iterations
int32_t m_codelen; // code length
float64_t m_pposone; // probability of +1
int32_t m_maxiter; ///< max number of iterations
int32_t m_codelen; ///< code length
float64_t m_pposone; ///< probability of +1

private:
/** ensure probability sum to one
Expand Down
4 changes: 4 additions & 0 deletions src/shogun/multiclass/ecoc/ECOCSimpleDecoder.h
Expand Up @@ -17,6 +17,10 @@
namespace shogun
{

/** A decoder that computes some simple distances between
* the binary classification results and the codes to select
* the class with the smallest distance.
*/
class CECOCSimpleDecoder: public CECOCDecoder
{
public:
Expand Down
2 changes: 1 addition & 1 deletion src/shogun/multiclass/ecoc/ECOCStrategy.cpp
Expand Up @@ -40,7 +40,7 @@ CECOCStrategy::~CECOCStrategy()
SG_UNREF(m_decoder);
}

void CECOCStrategy::train_start(CLabels *orig_labels, CLabels *train_labels)
void CECOCStrategy::train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels)
{
CMulticlassStrategy::train_start(orig_labels, train_labels);

Expand Down
4 changes: 3 additions & 1 deletion src/shogun/multiclass/ecoc/ECOCStrategy.h
Expand Up @@ -18,6 +18,7 @@
namespace shogun
{

/** Multiclass Strategy that uses ECOC coding */
class CECOCStrategy: public CMulticlassStrategy
{
public:
Expand All @@ -37,7 +38,7 @@ class CECOCStrategy: public CMulticlassStrategy
}

/** start training */
virtual void train_start(CLabels *orig_labels, CLabels *train_labels);
virtual void train_start(CMulticlassLabels *orig_labels, CBinaryLabels *train_labels);

/** has more training phase */
virtual bool train_has_more();
Expand Down Expand Up @@ -66,6 +67,7 @@ class CECOCStrategy: public CMulticlassStrategy
SGMatrix<int32_t> m_codebook;

private:
/** init parameters */
void init();
};

Expand Down
1 change: 1 addition & 0 deletions src/shogun/multiclass/ecoc/ECOCUtil.h
Expand Up @@ -16,6 +16,7 @@
namespace shogun
{

/** A helper class for some ECOC related procedures. */
class CECOCUtil
{
public:
Expand Down

0 comments on commit 6c4cdd5

Please sign in to comment.