Skip to content

Commit

Permalink
Renamed RealLabels to RegressionLabels
Browse files Browse the repository at this point in the history
  • Loading branch information
lisitsyn committed May 21, 2012
1 parent 60b2900 commit d91047e
Show file tree
Hide file tree
Showing 43 changed files with 162 additions and 154 deletions.
1 change: 0 additions & 1 deletion src/interfaces/modular/Evaluation_includes.i
@@ -1,5 +1,4 @@
%{
#include <shogun/labels/Labels.h>
#include <shogun/evaluation/Evaluation.h>
#include <shogun/evaluation/BinaryClassEvaluation.h>
#include <shogun/evaluation/ClusteringEvaluation.h>
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/modular/Features.i
Expand Up @@ -364,7 +364,7 @@ namespace shogun
%include <shogun/labels/DenseLabels.h>
%include <shogun/labels/BinaryLabels.h>
%include <shogun/labels/MulticlassLabels.h>
%include <shogun/labels/RealLabels.h>
%include <shogun/labels/RegressionLabels.h>
%include <shogun/features/RealFileFeatures.h>
%include <shogun/features/FKFeatures.h>
%include <shogun/features/TOPFeatures.h>
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/modular/Features_includes.i
Expand Up @@ -22,7 +22,7 @@
#include <shogun/labels/DenseLabels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/MulticlassLabels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/features/RealFileFeatures.h>
#include <shogun/features/RealFileFeatures.h>
#include <shogun/features/FKFeatures.h>
Expand Down
17 changes: 13 additions & 4 deletions src/interfaces/modular/Machine.i
Expand Up @@ -18,6 +18,15 @@ namespace shogun {
return CMulticlassLabels::obtain_from_generic($self->apply_multiclass(data));
}
}

%extend CLinearMulticlassMachine
{
CMulticlassLabels* apply(CFeatures* data=NULL)
{
return CMulticlassLabels::obtain_from_generic($self->apply_multiclass(data));
}
}


/*%extend COnlineLinearMachine
{
Expand All @@ -29,17 +38,17 @@ namespace shogun {

%extend CLinearMachine
{
CRealLabels* apply(CFeatures* data=NULL)
CRegressionLabels* apply(CFeatures* data=NULL)
{
return CRealLabels::obtain_from_generic($self->apply_regression(data));
return CRegressionLabels::obtain_from_generic($self->apply_regression(data));
}
}

%extend CKernelMachine
{
CRealLabels* apply(CFeatures* data=NULL)
CRegressionLabels* apply(CFeatures* data=NULL)
{
return CRealLabels::obtain_from_generic($self->apply_regression(data));
return CRegressionLabels::obtain_from_generic($self->apply_regression(data));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/shogun/classifier/PluginEstimate.cpp
Expand Up @@ -13,7 +13,7 @@
#include <shogun/features/StringFeatures.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/distributions/LinearHMM.h>
#include <shogun/classifier/PluginEstimate.h>

Expand Down Expand Up @@ -110,7 +110,7 @@ CLabels* CPluginEstimate::apply(CFeatures* data)
}

ASSERT(features);
CRealLabels* result=new CRealLabels(features->get_num_vectors());
CRegressionLabels* result=new CRegressionLabels(features->get_num_vectors());
ASSERT(result->get_num_labels()==features->get_num_vectors());

for (int32_t vec=0; vec<features->get_num_vectors(); vec++)
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/classifier/svm/WDSVMOcas.cpp
Expand Up @@ -21,7 +21,7 @@
#include <shogun/features/Alphabet.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>

using namespace shogun;

Expand Down Expand Up @@ -120,7 +120,7 @@ CLabels* CWDSVMOcas::apply(CFeatures* data)
int32_t num=features->get_num_vectors();
ASSERT(num>0);

CRealLabels* output=new CRealLabels(num);
CRegressionLabels* output=new CRegressionLabels(num);
SG_REF(output);

for (int32_t i=0; i<num; i++)
Expand Down
4 changes: 2 additions & 2 deletions src/shogun/evaluation/MeanAbsoluteError.cpp
Expand Up @@ -9,7 +9,7 @@

#include <shogun/evaluation/MeanAbsoluteError.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/mathematics/Math.h>

using namespace shogun;
Expand All @@ -23,7 +23,7 @@ float64_t CMeanAbsoluteError::evaluate(CLabels* predicted, CLabels* ground_truth
int32_t length = predicted->get_num_labels();
float64_t mae = 0.0;
for (int32_t i=0; i<length; i++)
mae += CMath::abs(((CRealLabels*) predicted)->get_label(i) - ((CRealLabels*) ground_truth)->get_label(i));
mae += CMath::abs(((CRegressionLabels*) predicted)->get_label(i) - ((CRegressionLabels*) ground_truth)->get_label(i));
mae /= length;
return mae;
}
4 changes: 2 additions & 2 deletions src/shogun/evaluation/MeanSquaredError.cpp
Expand Up @@ -10,7 +10,7 @@

#include <shogun/evaluation/MeanSquaredError.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/mathematics/Math.h>

using namespace shogun;
Expand All @@ -24,7 +24,7 @@ float64_t CMeanSquaredError::evaluate(CLabels* predicted, CLabels* ground_truth)
int32_t length = predicted->get_num_labels();
float64_t mse = 0.0;
for (int32_t i=0; i<length; i++)
mse += CMath::sq(((CRealLabels*) predicted)->get_label(i) - ((CRealLabels*) ground_truth)->get_label(i));
mse += CMath::sq(((CRegressionLabels*) predicted)->get_label(i) - ((CRegressionLabels*) ground_truth)->get_label(i));
mse /= length;
return mse;
}
6 changes: 3 additions & 3 deletions src/shogun/evaluation/MeanSquaredLogError.cpp
Expand Up @@ -10,7 +10,7 @@

#include <shogun/evaluation/MeanSquaredLogError.h>
#include <shogun/labels/Labels.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/mathematics/Math.h>

using namespace shogun;
Expand All @@ -26,8 +26,8 @@ float64_t CMeanSquaredLogError::evaluate(CLabels* predicted, CLabels* ground_tru
float64_t msle=0.0;
for (int32_t i=0; i<length; i++)
{
float64_t prediction=((CRealLabels*) predicted)->get_label(i);
float64_t truth=((CRealLabels*) ground_truth)->get_label(i);
float64_t prediction=((CRegressionLabels*) predicted)->get_label(i);
float64_t truth=((CRegressionLabels*) ground_truth)->get_label(i);

if (prediction<=-1.0 || truth<=-1.0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/evaluation/PRCEvaluation.cpp
Expand Up @@ -9,7 +9,7 @@
*/

#include <shogun/evaluation/PRCEvaluation.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/mathematics/Math.h>

Expand All @@ -34,7 +34,7 @@ float64_t CPRCEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth)
int32_t pos_count=0;

// initialize number of labels and labels
SGVector<float64_t> orig_labels = ((CRealLabels*) predicted)->get_labels();
SGVector<float64_t> orig_labels = ((CRegressionLabels*) predicted)->get_labels();
int32_t length = orig_labels.vlen;
float64_t* labels = CMath::clone_vector(orig_labels.vector, length);

Expand Down Expand Up @@ -74,7 +74,7 @@ float64_t CPRCEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth)
// recall (y)
m_PRC_graph[2*i+1] = tp/float64_t(pos_count);

m_thresholds[i]= ((CRealLabels*) predicted)->get_label(idxs[i]);
m_thresholds[i]= ((CRegressionLabels*) predicted)->get_label(idxs[i]);
}

// calc auRPC using area under curve
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/evaluation/ROCEvaluation.cpp
Expand Up @@ -9,7 +9,7 @@
*/

#include <shogun/evaluation/ROCEvaluation.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/labels/BinaryLabels.h>
#include <shogun/mathematics/Math.h>

Expand Down Expand Up @@ -38,7 +38,7 @@ float64_t CROCEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth)
int32_t neg_count=0;

// initialize number of labels and labels
SGVector<float64_t> orig_labels = ((CRealLabels*) predicted)->get_labels();
SGVector<float64_t> orig_labels = predicted->get_confidences();
int32_t length = orig_labels.vlen;
float64_t* labels = CMath::clone_vector(orig_labels.vector, length);

Expand Down Expand Up @@ -84,7 +84,7 @@ float64_t CROCEvaluation::evaluate(CLabels* predicted, CLabels* ground_truth)
// create ROC curve and calculate auROC
for(i=0; i<length; i++)
{
label = ((CRealLabels*) predicted)->get_label(idxs[i]);
label = ((CRegressionLabels*) predicted)->get_label(idxs[i]);

if (label != threshold)
{
Expand Down
10 changes: 5 additions & 5 deletions src/shogun/features/SparseFeatures.cpp
Expand Up @@ -2,7 +2,7 @@
#include <shogun/preprocessor/SparsePreprocessor.h>
#include <shogun/mathematics/Math.h>
#include <shogun/lib/DataType.h>
#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/io/SGIO.h>

#include <string.h>
Expand Down Expand Up @@ -742,12 +742,12 @@ template<class ST> float64_t CSparseFeatures<ST>::compute_squared_norm(
return CMath::abs(result);
}

template<class ST> CRealLabels* CSparseFeatures<ST>::load_svmlight_file(char* fname,
template<class ST> CRegressionLabels* CSparseFeatures<ST>::load_svmlight_file(char* fname,
bool do_sort_features)
{
remove_all_subsets();

CRealLabels* lab=NULL;
CRegressionLabels* lab=NULL;

size_t blocksize=1024*1024;
size_t required_blocksize=blocksize;
Expand Down Expand Up @@ -789,7 +789,7 @@ template<class ST> CRealLabels* CSparseFeatures<ST>::load_svmlight_file(char* fn
blocksize=required_blocksize;
dummy = SG_MALLOC(uint8_t, blocksize+1); //allow setting of '\0' at EOL

lab=new CRealLabels(num_vectors);
lab=new CRegressionLabels(num_vectors);
sparse_feature_matrix=SG_MALLOC(SGSparseVector<ST>, num_vectors);

rewind(f);
Expand Down Expand Up @@ -953,7 +953,7 @@ template<class ST> void CSparseFeatures<ST>::sort_features()
}

template<class ST> bool CSparseFeatures<ST>::write_svmlight_file(char* fname,
CRealLabels* label)
CRegressionLabels* label)
{
if (m_subset_stack->has_subsets())
SG_ERROR("write_svmlight_file() not allowed with subset\n");
Expand Down
8 changes: 4 additions & 4 deletions src/shogun/features/SparseFeatures.h
Expand Up @@ -20,7 +20,7 @@
#include <shogun/lib/Cache.h>
#include <shogun/io/File.h>

#include <shogun/labels/RealLabels.h>
#include <shogun/labels/RegressionLabels.h>
#include <shogun/features/Features.h>
#include <shogun/features/DotFeatures.h>
#include <shogun/features/DenseFeatures.h>
Expand All @@ -29,7 +29,7 @@ namespace shogun
{

class CFile;
class CRealLabels;
class CRegressionLabels;
class CFeatures;
class CDotFeatures;
template <class ST> class CDenseFeatures;
Expand Down Expand Up @@ -418,7 +418,7 @@ template <class ST> class CSparseFeatures : public CDotFeatures
* are in ascending order
* @return label object with corresponding labels
*/
CRealLabels* load_svmlight_file(char* fname, bool do_sort_features=true);
CRegressionLabels* load_svmlight_file(char* fname, bool do_sort_features=true);

/** ensure that features occur in ascending order, only call when no
* preprocessors are attached
Expand All @@ -435,7 +435,7 @@ template <class ST> class CSparseFeatures : public CDotFeatures
* @param label Label object (number of labels must correspond to number of features)
* @return true if successful
*/
bool write_svmlight_file(char* fname, CRealLabels* label);
bool write_svmlight_file(char* fname, CRegressionLabels* label);

/** obtain the dimensionality of the feature space
*
Expand Down
43 changes: 0 additions & 43 deletions src/shogun/labels/RealLabels.cpp

This file was deleted.

43 changes: 43 additions & 0 deletions src/shogun/labels/RegressionLabels.cpp
@@ -0,0 +1,43 @@
#include <shogun/labels/DenseLabels.h>
#include <shogun/labels/RegressionLabels.h>

using namespace shogun;

CRegressionLabels::CRegressionLabels() : CDenseLabels()
{
}

CRegressionLabels::CRegressionLabels(int32_t num_labels) : CDenseLabels(num_labels)
{
}

CRegressionLabels::CRegressionLabels(const SGVector<float64_t> src) : CDenseLabels()
{
set_labels(src);
}

CRegressionLabels::CRegressionLabels(CFile* loader) : CDenseLabels(loader)
{
}

CRegressionLabels* CRegressionLabels::obtain_from_generic(CLabels* base_labels)
{
if ( base_labels->get_label_type() == LT_REAL )
return (CRegressionLabels*) base_labels;
else
SG_SERROR("base_labels must be of dynamic type CRegressionLabels");

return NULL;
}

bool CRegressionLabels::is_valid()
{
ASSERT(m_labels.vector);
return true;
}

ELabelType CRegressionLabels::get_label_type()
{
return LT_REAL;
}

0 comments on commit d91047e

Please sign in to comment.