Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added custom evaluations support for model selection output
  • Loading branch information
lisitsyn committed Jul 25, 2012
1 parent 5b3d566 commit 086ee0a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/shogun/evaluation/CrossValidation.cpp
Expand Up @@ -217,6 +217,7 @@ float64_t CCrossValidation::evaluate_one_run(CModelSelectionOutput* ms_output)

if (ms_output)
{
ms_output->output_custom_evaluations(result_labels, m_labels);
ms_output->output_test_indices(subset_indices);
ms_output->output_test_result(result_labels);
ms_output->output_test_true_result(m_labels);
Expand Down
23 changes: 23 additions & 0 deletions src/shogun/modelselection/ModelSelectionOutput.cpp
Expand Up @@ -13,6 +13,7 @@
#include <shogun/machine/LinearMulticlassMachine.h>
#include <shogun/machine/KernelMachine.h>
#include <shogun/machine/KernelMulticlassMachine.h>
#include <shogun/evaluation/MulticlassAccuracy.h>

using namespace shogun;

Expand Down Expand Up @@ -75,3 +76,25 @@ void CModelSelectionOutput::output_evaluate_result(float64_t result)
{
SG_PRINT("evaluation result = %f\n",result);
}

void CModelSelectionOutput::add_custom_evaluation(CEvaluation* evaluation)
{
m_custom_evaluations->append_element(evaluation);
}

void CModelSelectionOutput::output_custom_evaluations(CLabels* result, CLabels* truth)
{
for (int32_t i=0; i<m_custom_evaluations->get_num_elements(); i++)
{
CEvaluation* custom_evaluation = (CEvaluation*)m_custom_evaluations->get_element(i);
float64_t eval = custom_evaluation->evaluate(result, truth);
SG_PRINT("%s evaluation result = %f\n",custom_evaluation->get_name(),eval);
// dirty hack for confusion matrix
if (dynamic_cast<CMulticlassAccuracy*>(custom_evaluation))
{
((CMulticlassAccuracy*)custom_evaluation)->get_confusion_matrix(result, truth).display_matrix("confusion_matrix");
}
SG_UNREF(custom_evaluation);
}
}

8 changes: 8 additions & 0 deletions src/shogun/modelselection/ModelSelectionOutput.h
Expand Up @@ -14,6 +14,7 @@
#include <shogun/machine/Machine.h>
#include <shogun/lib/SGVector.h>
#include <shogun/labels/Labels.h>
#include <shogun/evaluation/Evaluation.h>

namespace shogun
{
Expand All @@ -39,6 +40,13 @@ class CModelSelectionOutput: public CSGObject
void output_test_true_result(CLabels* results);
void output_evaluate_result(float64_t result);

void add_custom_evaluation(CEvaluation* evaluation);
void output_custom_evaluations(CLabels* results, CLabels* truth);

protected:

CDynamicObjectArray* m_custom_evaluations;

};

}
Expand Down

0 comments on commit 086ee0a

Please sign in to comment.