Skip to content

Commit

Permalink
Added Margin Loss Decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
pluskid committed May 20, 2012
1 parent 788043e commit bf4e97f
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
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 bf4e97f

Please sign in to comment.