Skip to content

Commit

Permalink
Merge pull request #534 from pluskid/multiclass-ecoc
Browse files Browse the repository at this point in the history
Multiclass ecoc
  • Loading branch information
Soeren Sonnenburg committed May 20, 2012
2 parents 0fbded0 + 3fe856d commit 6f79da5
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/interfaces/modular/Multiclass.i
Expand Up @@ -34,6 +34,7 @@
%rename(ECOCIHDDecoder) CECOCIHDDecoder;
%rename(ECOCEDDecoder) CECOCEDDecoder;
%rename(ECOCAEDDecoder) CECOCAEDDecoder;
%rename(ECOCLLBDecoder) CECOCLLBDecoder;

%rename(MulticlassLibLinear) CMulticlassLibLinear;
%rename(MulticlassOCAS) CMulticlassOCAS;
Expand Down Expand Up @@ -69,6 +70,7 @@
%include <shogun/multiclass/ecoc/ECOCIHDDecoder.h>
%include <shogun/multiclass/ecoc/ECOCEDDecoder.h>
%include <shogun/multiclass/ecoc/ECOCAEDDecoder.h>
%include <shogun/multiclass/ecoc/ECOCLLBDecoder.h>
%include <shogun/multiclass/ecoc/ECOCStrategy.h>

%include <shogun/multiclass/MulticlassLibLinear.h>
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/modular/Multiclass_includes.i
Expand Up @@ -23,6 +23,7 @@
#include <shogun/multiclass/ecoc/ECOCIHDDecoder.h>
#include <shogun/multiclass/ecoc/ECOCEDDecoder.h>
#include <shogun/multiclass/ecoc/ECOCAEDDecoder.h>
#include <shogun/multiclass/ecoc/ECOCLLBDecoder.h>

#include <shogun/multiclass/MulticlassLibLinear.h>
#include <shogun/multiclass/MulticlassOCAS.h>
Expand Down
11 changes: 11 additions & 0 deletions src/shogun/multiclass/ecoc/ECOCLLBDecoder.cpp
@@ -0,0 +1,11 @@
#include <shogun/multiclass/ecoc/ECOCLLBDecoder.h>

using namespace shogun;

float64_t CECOCLLBDecoder::compute_distance(SGVector<float64_t> outputs, const int32_t *code)
{
float64_t loss = 0;
for (int32_t i=0; i < outputs.vlen; ++i)
loss += outputs[i]*code[i];
return -loss;
}
46 changes: 46 additions & 0 deletions src/shogun/multiclass/ecoc/ECOCLLBDecoder.h
@@ -0,0 +1,46 @@
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* Written (W) 2012 Chiyuan Zhang
* Copyright (C) 2012 Chiyuan Zhang
*/

#ifndef ECOCLLBDECODER_H__
#define ECOCLLBDECODER_H__

#include <shogun/multiclass/ecoc/ECOCSimpleDecoder.h>

namespace shogun
{

/** Margin Loss based decoder.
* Using OVREncoder with this Decoder should be equivlalent to
* traditional OVR Strategy.
*/
class CECOCLLBDecoder: public CECOCSimpleDecoder
{
public:
/** constructor */
CECOCLLBDecoder() {}

/** destructor */
virtual ~CECOCLLBDecoder() {}

/** get name */
virtual const char* get_name() const { return "ECOCLLBDecoder"; }

protected:
/** whether to turn the output into binary before decoding */
virtual bool binary_decoding() { return false; }

/** compute distance */
virtual float64_t compute_distance(SGVector<float64_t> outputs, const int32_t *code)=0;
};

} /* shogun */

#endif /* end of include guard: ECOCLLBDECODER_H__ */

0 comments on commit 6f79da5

Please sign in to comment.