Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #524 from pluskid/multiclass-ecoc
Multiclass ecoc
- Loading branch information
Showing
19 changed files
with
403 additions
and
73 deletions.
There are no files selected for viewing
23 changes: 3 additions & 20 deletions
23
examples/undocumented/python_modular/classifier_multiclass_ecoc_discriminant.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
examples/undocumented/python_modular/classifier_multiclass_shared.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
def prepare_data(use_toy=True): | ||
from os.path import exists | ||
from tools.load import LoadMatrix | ||
lm=LoadMatrix() | ||
|
||
if not use_toy and exists('../data/../mldata/uci-20070111-optdigits.mat'): | ||
from scipy.io import loadmat | ||
|
||
mat = loadmat('../data/../mldata/uci-20070111-optdigits.mat')['int0'].astype(float) | ||
X = mat[:-1,:] | ||
Y = mat[-1,:] | ||
isplit = X.shape[1]/2 | ||
traindat = X[:,:isplit] | ||
label_traindat = Y[:isplit] | ||
testdat = X[:, isplit:] | ||
label_testdat = Y[isplit:] | ||
else: | ||
traindat = lm.load_numbers('../data/fm_train_real.dat') | ||
testdat = lm.load_numbers('../data/fm_test_real.dat') | ||
label_traindat = lm.load_labels('../data/label_train_multiclass.dat') | ||
label_testdat = None | ||
|
||
return [traindat, label_traindat, testdat, label_testdat] |
7 changes: 2 additions & 5 deletions
7
examples/undocumented/python_modular/classifier_multiclassliblinear_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
examples/undocumented/python_modular/classifier_multiclasslibsvm_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
examples/undocumented/python_modular/classifier_multiclasslinearmachine_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
examples/undocumented/python_modular/classifier_multiclassmachine_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 2 additions & 5 deletions
7
examples/undocumented/python_modular/classifier_multiclassocas_modular.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* 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 ECOCAEDDECODER_H__ | ||
#define ECOCAEDDECODER_H__ | ||
|
||
|
||
#include <shogun/multiclass/ecoc/ECOCSimpleDecoder.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** Attenuated Euclidean Distance Decoder. | ||
* | ||
* \f[ | ||
* AED(q, b_i) = \sqrt{\sum_{j=1}^n (q^j-b_i^j)^2 |b_i^j|} | ||
* \f] | ||
*/ | ||
class CECOCAEDDecoder: public CECOCSimpleDecoder | ||
{ | ||
public: | ||
/** constructor */ | ||
CECOCAEDDecoder() {} | ||
|
||
/** destructor */ | ||
virtual ~CECOCAEDDecoder() {} | ||
|
||
/** get name */ | ||
virtual const char* get_name() const { return "ECOCAEDDecoder"; } | ||
|
||
|
||
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) | ||
{ | ||
float64_t dist = 0; | ||
for (int32_t i=0; i < outputs.vlen; ++i) | ||
dist += (outputs[i]-code[i])*(outputs[i]-code[i]) * CMath::abs(code[i]); | ||
return CMath::sqrt(dist); | ||
} | ||
}; | ||
|
||
} /* shogun */ | ||
|
||
|
||
#endif /* end of include guard: ECOCAEDDECODER_H__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 ECOCEDDECODER_H__ | ||
#define ECOCEDDECODER_H__ | ||
|
||
#include <shogun/multiclass/ecoc/ECOCSimpleDecoder.h> | ||
#include <shogun/mathematics/Math.h> | ||
|
||
namespace shogun | ||
{ | ||
|
||
/** Euclidean Distance Decoder. | ||
* | ||
* \f[ | ||
* ED(q, b_i) = \sqrt{\sum_{j=1}^n (q^j-b_i^j)^2} | ||
* \f] | ||
*/ | ||
class CECOCEDDecoder: public CECOCSimpleDecoder | ||
{ | ||
public: | ||
/** constructor */ | ||
CECOCEDDecoder() {} | ||
|
||
/** destructor */ | ||
virtual ~CECOCEDDecoder() {} | ||
|
||
/** get name */ | ||
virtual const char* get_name() const { return "ECOCEDDecoder"; } | ||
|
||
|
||
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) | ||
{ | ||
float64_t dist = 0; | ||
for (int32_t i=0; i < outputs.vlen; ++i) | ||
dist += (outputs[i]-code[i])*(outputs[i]-code[i]); | ||
return CMath::sqrt(dist); | ||
} | ||
}; | ||
|
||
} /* shogun */ | ||
|
||
#endif /* end of include guard: ECOCEDDECODER_H__ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.