From acb3e4d7afdd2620d66ac87cb9dadad80de599b5 Mon Sep 17 00:00:00 2001
From: Arnaud Jaen <arnaud.jaen@c-s.fr>
Date: Wed, 20 Mar 2013 16:48:42 +0100
Subject: [PATCH] TEST: Add tests on Machine Learning.

---
 Code/UtilitiesAdapters/CMakeLists.txt         |   6 +-
 .../otbRandomForestsMachineLearningModel.txx  |  10 +-
 Testing/Code/Learning/CMakeLists.txt          |  64 ++++
 Testing/Code/Learning/otbLearningTests6.cxx   |  35 ++
 .../Learning/otbTrainMachineLearningModel.cxx | 362 ++++++++++++++++++
 5 files changed, 474 insertions(+), 3 deletions(-)
 create mode 100644 Testing/Code/Learning/otbLearningTests6.cxx
 create mode 100644 Testing/Code/Learning/otbTrainMachineLearningModel.cxx

diff --git a/Code/UtilitiesAdapters/CMakeLists.txt b/Code/UtilitiesAdapters/CMakeLists.txt
index 90a65b790c..27a6ca4f40 100644
--- a/Code/UtilitiesAdapters/CMakeLists.txt
+++ b/Code/UtilitiesAdapters/CMakeLists.txt
@@ -4,7 +4,11 @@ ADD_SUBDIRECTORY(TinyXMLAdapters)
 ADD_SUBDIRECTORY(OGRAdapters)
 ADD_SUBDIRECTORY(boost)
 ADD_SUBDIRECTORY(ITKPendingPatches)
-ADD_SUBDIRECTORY(OpenCV)
+
+IF(OTB_USE_OPENCV)
+  ADD_SUBDIRECTORY(OpenCV)
+ENDIF(OTB_USE_OPENCV)
+
 
 IF(NOT OTB_INSTALL_NO_DEVELOPMENT)
   FILE(GLOB __files1 "${CMAKE_CURRENT_SOURCE_DIR}/*.h")
diff --git a/Code/UtilitiesAdapters/OpenCV/otbRandomForestsMachineLearningModel.txx b/Code/UtilitiesAdapters/OpenCV/otbRandomForestsMachineLearningModel.txx
index 32debbf588..25454bf0d8 100644
--- a/Code/UtilitiesAdapters/OpenCV/otbRandomForestsMachineLearningModel.txx
+++ b/Code/UtilitiesAdapters/OpenCV/otbRandomForestsMachineLearningModel.txx
@@ -118,7 +118,10 @@ void
 RandomForestsMachineLearningModel<TInputValue,TOutputValue>
 ::Save(const std::string & filename, const std::string & name)
 {
-  m_RFModel->save(filename.c_str(), name.c_str());
+  if (name == "")
+    m_RFModel->save(filename.c_str(), 0);
+  else
+    m_RFModel->save(filename.c_str(), name.c_str());
 }
 
 template <class TInputValue, class TOutputValue>
@@ -126,7 +129,10 @@ void
 RandomForestsMachineLearningModel<TInputValue,TOutputValue>
 ::Load(const std::string & filename, const std::string & name)
 {
-  m_RFModel->load(filename.c_str(), name.c_str());
+  if (name == "")
+    m_RFModel->load(filename.c_str(), 0);
+  else
+    m_RFModel->load(filename.c_str(), name.c_str());
 }
 
 template <class TInputValue, class TOutputValue>
diff --git a/Testing/Code/Learning/CMakeLists.txt b/Testing/Code/Learning/CMakeLists.txt
index 50ee23c693..4e401ce909 100644
--- a/Testing/Code/Learning/CMakeLists.txt
+++ b/Testing/Code/Learning/CMakeLists.txt
@@ -7,6 +7,9 @@ SET(LEARNING_TESTS2 ${CXX_TEST_PATH}/otbLearningTests2)
 SET(LEARNING_TESTS3 ${CXX_TEST_PATH}/otbLearningTests3)
 SET(LEARNING_TESTS4 ${CXX_TEST_PATH}/otbLearningTests4)
 SET(LEARNING_TESTS5 ${CXX_TEST_PATH}/otbLearningTests5)
+IF(OTB_USE_OPENCV)
+	SET(LEARNING_TESTS6 ${CXX_TEST_PATH}/otbLearningTests6)
+ENDIF(OTB_USE_OPENCV)	
 
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbLearningTESTS1 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -674,6 +677,55 @@ otbNeighborhoodMajorityVotingImageFilterTest
  )
 
 
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ otbLearningTESTS6 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+IF(OTB_USE_OPENCV)
+	ADD_TEST(leTuRandomForestsMachineLearningModelNew ${LEARNING_TESTS6}
+           otbRandomForestsMachineLearningModelNew)
+
+
+	ADD_TEST(leTvRandomForestsMachineLearningModel ${LEARNING_TESTS6}
+         #--compare-ascii ${NOTOL}
+         #${BASELINE_FILES}/RandomForestsMachineLearningModel.txt
+         #${TEMP}/RandomForestsMachineLearningModel.txt
+         otbRandomForestsMachineLearningModel
+         ${INPUTDATA}/letter.scale
+         ${TEMP}/RandomForestsMachineLearningModel.txt
+         )
+
+	ADD_TEST(leTuKNearestNeighborsMachineLearningModelNew ${LEARNING_TESTS6}
+           otbKNearestNeighborsMachineLearningModelNew)
+           
+	ADD_TEST(leTvKNearestNeighborsMachineLearningModel ${LEARNING_TESTS6}
+         otbKNearestNeighborsMachineLearningModel
+         ${INPUTDATA}/letter.scale)
+
+	ADD_TEST(leTuSVMMachineLearningModelNew ${LEARNING_TESTS6}
+           otbSVMMachineLearningModelNew)
+
+	ADD_TEST(leTvSVMMachineLearningModel ${LEARNING_TESTS6}
+		 --compare-ascii ${NOTOL}
+         ${BASELINE_FILES}/svm_model.txt
+         ${TEMP}/svm_model.txt
+         otbSVMMachineLearningModel
+         ${INPUTDATA}/letter.scale
+         ${TEMP}/svm_model.txt
+         )
+
+	ADD_TEST(leTuLibSVMMachineLearningModelNew ${LEARNING_TESTS6}
+       	 otbLibSVMMachineLearningModelNew)
+           
+	ADD_TEST(leTvLibSVMMachineLearningModel ${LEARNING_TESTS6}
+		 --compare-ascii ${NOTOL}
+	     ${BASELINE_FILES}/libsvm_model.txt
+	     ${TEMP}/libsvm_model.txt
+	     otbLibSVMMachineLearningModel
+	     ${INPUTDATA}/letter.scale
+	     ${TEMP}/libsvm_model.txt
+     )
+ENDIF(OTB_USE_OPENCV)
+
 # Testing srcs
 SET(BasicLearning_SRCS1
 otbLearningTests1.cxx
@@ -755,12 +807,24 @@ otbNeighborhoodMajorityVotingImageFilterNew.cxx
 otbNeighborhoodMajorityVotingImageFilterTest.cxx
 )
 
+IF(OTB_USE_OPENCV)
+	SET(BasicLearning_SRCS6
+	otbLearningTests6.cxx
+	otbTrainMachineLearningModel.cxx
+	)
+ENDIF(OTB_USE_OPENCV)
+
 OTB_ADD_EXECUTABLE(otbLearningTests1 "${BasicLearning_SRCS1}" "OTBLearning;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbLearningTests2 "${BasicLearning_SRCS2}" "OTBLearning;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbLearningTests3 "${BasicLearning_SRCS3}" "OTBLearning;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbLearningTests4 "${BasicLearning_SRCS4}" "OTBLearning;OTBIO;OTBTesting")
 OTB_ADD_EXECUTABLE(otbLearningTests5 "${BasicLearning_SRCS5}" "OTBLearning;OTBIO;OTBTesting")
 
+IF(OTB_USE_OPENCV)
+	OTB_ADD_EXECUTABLE(otbLearningTests6 "${BasicLearning_SRCS6}" "OTBMachineLearning;OTBLearning;OTBIO;OTBTesting")
+ENDIF(OTB_USE_OPENCV)
+
+
 ENDIF( NOT OTB_DISABLE_CXX_TESTING AND BUILD_TESTING )
 
 
diff --git a/Testing/Code/Learning/otbLearningTests6.cxx b/Testing/Code/Learning/otbLearningTests6.cxx
new file mode 100644
index 0000000000..7643f2c0b0
--- /dev/null
+++ b/Testing/Code/Learning/otbLearningTests6.cxx
@@ -0,0 +1,35 @@
+/*=========================================================================
+
+  Program:   ORFEO Toolbox
+  Language:  C++
+  Date:      $Date$
+  Version:   $Revision$
+
+
+  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+  See OTBCopyright.txt for details.
+
+
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+
+=========================================================================*/
+
+// this file defines the otbCommonTest for the test driver
+// and all it expects is that you have a function called RegisterTests
+
+
+#include "otbTestMain.h"
+
+void RegisterTests()
+{
+  REGISTER_TEST(otbLibSVMMachineLearningModelNew);
+  REGISTER_TEST(otbLibSVMMachineLearningModel);
+  REGISTER_TEST(otbSVMMachineLearningModelNew);
+  REGISTER_TEST(otbSVMMachineLearningModel);
+  REGISTER_TEST(otbKNearestNeighborsMachineLearningModelNew);
+  REGISTER_TEST(otbKNearestNeighborsMachineLearningModel);
+  REGISTER_TEST(otbRandomForestsMachineLearningModelNew);
+  REGISTER_TEST(otbRandomForestsMachineLearningModel);
+}
diff --git a/Testing/Code/Learning/otbTrainMachineLearningModel.cxx b/Testing/Code/Learning/otbTrainMachineLearningModel.cxx
new file mode 100644
index 0000000000..c564d08df1
--- /dev/null
+++ b/Testing/Code/Learning/otbTrainMachineLearningModel.cxx
@@ -0,0 +1,362 @@
+/*=========================================================================
+
+ Program:   ORFEO Toolbox
+ Language:  C++
+ Date:      $Date$
+ Version:   $Revision$
+
+
+ Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
+ See OTBCopyright.txt for details.
+
+
+ This software is distributed WITHOUT ANY WARRANTY; without even
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ PURPOSE.  See the above copyright notices for more information.
+
+ =========================================================================*/
+
+#include <fstream>
+#include <string>
+#include <algorithm>
+
+#include "otbMachineLearningModel.h"
+#include "otbLibSVMMachineLearningModel.h"
+#include "otbSVMMachineLearningModel.h"
+#include "otbKNearestNeighborsMachineLearningModel.h"
+#include "otbRandomForestsMachineLearningModel.h"
+
+#include "otbConfusionMatrixCalculator.h"
+
+
+typedef otb::MachineLearningModel<float,short>         MachineLearningModelType;
+typedef MachineLearningModelType::InputValueType       InputValueType;
+typedef MachineLearningModelType::InputSampleType      InputSampleType;
+typedef MachineLearningModelType::InputListSampleType  InputListSampleType;
+typedef MachineLearningModelType::TargetValueType      TargetValueType;
+typedef MachineLearningModelType::TargetSampleType     TargetSampleType;
+typedef MachineLearningModelType::TargetListSampleType TargetListSampleType;
+typedef otb::ConfusionMatrixCalculator<TargetListSampleType, TargetListSampleType> ConfusionMatrixCalculatorType;
+
+bool ReadDataFile(const std::string & infname, InputListSampleType * samples, TargetListSampleType * labels)
+{
+  std::ifstream ifs;
+  ifs.open(infname.c_str());
+
+  if(!ifs)
+    {
+    std::cout<<"Could not read file "<<infname<<std::endl;
+    return false;
+    }
+
+  unsigned int nbfeatures = 0;
+
+    while (!ifs.eof())
+      {
+      std::string line;
+      std::getline(ifs, line);
+
+      if(nbfeatures == 0)
+        {
+        nbfeatures = std::count(line.begin(),line.end(),' ')-1;
+        //std::cout<<"Found "<<nbfeatures<<" features per samples"<<std::endl;
+        }
+
+      if(line.size()>1)
+        {
+
+        InputSampleType sample(nbfeatures);
+        sample.Fill(0);
+
+        std::string::size_type pos = line.find_first_of(" ", 0);
+
+        // Parse label
+        TargetSampleType label;
+        label[0] = atoi(line.substr(0, pos).c_str());
+
+        bool endOfLine = false;
+
+        unsigned int id = 0;
+
+        while(!endOfLine)
+          {
+          std::string::size_type nextpos = line.find_first_of(" ", pos+1);
+
+          if(nextpos == std::string::npos)
+            {
+            endOfLine = true;
+            nextpos = line.size()-1;
+            }
+          else
+            {
+            std::string feature = line.substr(pos,nextpos-pos);
+            std::string::size_type semicolonpos = feature.find_first_of(":");
+            id = atoi(feature.substr(0,semicolonpos).c_str());
+            sample[id] = atof(feature.substr(semicolonpos+1,feature.size()-semicolonpos).c_str());
+            pos = nextpos;
+            }
+          }
+        samples->PushBack(sample);
+        labels->PushBack(label);
+        }
+      }
+
+    //std::cout<<"Retrieved "<<samples->Size()<<" samples"<<std::endl;
+
+  ifs.close();
+
+  return true;
+}
+
+int otbLibSVMMachineLearningModelNew(int argc, char * argv[])
+{
+  typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
+  SVMType::Pointer svmclassifier = SVMType::New();
+  return EXIT_SUCCESS;
+}
+
+int otbLibSVMMachineLearningModel(int argc, char * argv[])
+{
+  if (argc != 3)
+    {
+      std::cout<<"Wrong number of arguments "<<std::endl;
+      std::cout<<"Usage : sample file, output file "<<std::endl;
+      return EXIT_FAILURE;
+    }
+
+
+  typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
+  InputListSampleType::Pointer samples = InputListSampleType::New();
+  TargetListSampleType::Pointer labels = TargetListSampleType::New();
+  TargetListSampleType::Pointer predicted = TargetListSampleType::New();
+
+  if (!ReadDataFile(argv[1], samples, labels))
+    {
+    std::cout << "Failed to read samples file " << argv[1] << std::endl;
+    return EXIT_FAILURE;
+    }
+
+  SVMType::Pointer svmclassifier = SVMType::New();
+  svmclassifier->SetInputListSample(samples);
+  svmclassifier->SetTargetListSample(labels);
+  svmclassifier->Train();
+
+  svmclassifier->SetTargetListSample(predicted);
+  svmclassifier->PredictAll();
+
+  ConfusionMatrixCalculatorType::Pointer cmCalculator = ConfusionMatrixCalculatorType::New();
+
+  cmCalculator->SetProducedLabels(predicted);
+  cmCalculator->SetReferenceLabels(labels);
+  cmCalculator->Update();
+
+  std::cout << "Confusion matrix: " << std::endl;
+  std::cout << cmCalculator->GetConfusionMatrix() << std::endl;
+  std::cout << "Kappa: " << cmCalculator->GetKappaIndex() << std::endl;
+  std::cout << "Overall Accuracy: " << cmCalculator->GetOverallAccuracy() << std::endl;
+
+  svmclassifier->Save(argv[2]);
+
+  return EXIT_SUCCESS;
+}
+
+int otbSVMMachineLearningModelNew(int argc, char * argv[])
+{
+  typedef otb::SVMMachineLearningModel<InputValueType,TargetValueType> SVMType;
+  SVMType::Pointer svmclassifier = SVMType::New();
+  return EXIT_SUCCESS;
+}
+
+int otbSVMMachineLearningModel(int argc, char * argv[])
+{
+  if (argc != 3 )
+    {
+      std::cout<<"Wrong number of arguments "<<std::endl;
+      std::cout<<"Usage : sample file, output file "<<std::endl;
+      return EXIT_FAILURE;
+    }
+
+  typedef otb::LibSVMMachineLearningModel<InputValueType, TargetValueType> SVMType;
+
+  InputListSampleType::Pointer samples = InputListSampleType::New();
+  TargetListSampleType::Pointer labels = TargetListSampleType::New();
+  TargetListSampleType::Pointer predicted = TargetListSampleType::New();
+
+  if(!ReadDataFile(argv[1],samples,labels))
+    {
+    std::cout<<"Failed to read samples file "<<argv[1]<<std::endl;
+    return EXIT_FAILURE;
+    }
+
+  SVMType::Pointer svmclassifier = SVMType::New();
+  svmclassifier->SetInputListSample(samples);
+  svmclassifier->SetTargetListSample(labels);
+  svmclassifier->Train();
+
+  svmclassifier->SetTargetListSample(predicted);
+  svmclassifier->PredictAll();
+
+  svmclassifier->Save(argv[2]);
+
+  ConfusionMatrixCalculatorType::Pointer cmCalculator = ConfusionMatrixCalculatorType::New();
+
+  cmCalculator->SetProducedLabels(predicted);
+  cmCalculator->SetReferenceLabels(labels);
+  cmCalculator->Update();
+
+  std::cout<<"Confusion matrix: "<<std::endl;
+  std::cout<<cmCalculator->GetConfusionMatrix()<<std::endl;
+  std::cout<<"Kappa: "<<cmCalculator->GetKappaIndex()<<std::endl;
+  std::cout<<"Overall Accuracy: "<<cmCalculator->GetOverallAccuracy()<<std::endl;
+
+  return EXIT_SUCCESS;
+}
+
+int otbKNearestNeighborsMachineLearningModelNew(int argc, char * argv[])
+{
+  typedef otb::KNearestNeighborsMachineLearningModel<InputValueType,TargetValueType> KNearestNeighborsType;
+  KNearestNeighborsType::Pointer knnclassifier = KNearestNeighborsType::New();
+  return EXIT_SUCCESS;
+}
+
+int otbKNearestNeighborsMachineLearningModel(int argc, char * argv[])
+{
+  if (argc != 2 )
+    {
+      std::cout<<"Wrong number of arguments "<<std::endl;
+      std::cout<<"Usage : sample file"<<std::endl;
+      return EXIT_FAILURE;
+    }
+
+  typedef otb::KNearestNeighborsMachineLearningModel<InputValueType,TargetValueType> KNearestNeighborsType;
+  InputListSampleType::Pointer samples = InputListSampleType::New();
+  TargetListSampleType::Pointer labels = TargetListSampleType::New();
+  TargetListSampleType::Pointer predicted = TargetListSampleType::New();
+
+  if(!ReadDataFile(argv[1],samples,labels))
+    {
+    std::cout<<"Failed to read samples file "<<argv[1]<<std::endl;
+    return EXIT_FAILURE;
+    }
+
+  KNearestNeighborsType::Pointer knnclassifier = KNearestNeighborsType::New();
+  knnclassifier->SetInputListSample(samples);
+  knnclassifier->SetTargetListSample(labels);
+  knnclassifier->Train();
+
+  knnclassifier->SetTargetListSample(predicted);
+  knnclassifier->Superclass::PredictAll();
+
+  ConfusionMatrixCalculatorType::Pointer cmCalculator = ConfusionMatrixCalculatorType::New();
+
+  cmCalculator->SetProducedLabels(predicted);
+  cmCalculator->SetReferenceLabels(labels);
+  cmCalculator->Update();
+
+  std::cout<<"Confusion matrix: "<<std::endl;
+  std::cout<<cmCalculator->GetConfusionMatrix()<<std::endl;
+  std::cout<<"Kappa: "<<cmCalculator->GetKappaIndex()<<std::endl;
+  std::cout<<"Overall Accuracy: "<<cmCalculator->GetOverallAccuracy()<<std::endl;
+
+  //write the model
+  //knnclassifier->Save(argv[2]);
+
+  return EXIT_SUCCESS;
+}
+
+int otbRandomForestsMachineLearningModelNew(int argc, char * argv[])
+{
+  typedef otb::RandomForestsMachineLearningModel<InputValueType,TargetValueType> RandomForestType;
+  RandomForestType::Pointer rfclassifier = RandomForestType::New();
+  return EXIT_SUCCESS;
+}
+
+int otbRandomForestsMachineLearningModel(int argc, char * argv[])
+{
+  if (argc != 3 )
+  {
+    std::cout<<"Wrong number of arguments "<<std::endl;
+    std::cout<<"Usage : sample file, output file "<<std::endl;
+    return EXIT_FAILURE;
+  }
+
+  typedef otb::RandomForestsMachineLearningModel<InputValueType,TargetValueType> RandomForestType;
+  InputListSampleType::Pointer samples = InputListSampleType::New();
+  TargetListSampleType::Pointer labels = TargetListSampleType::New();
+  TargetListSampleType::Pointer predicted = TargetListSampleType::New();
+
+  if(!ReadDataFile(argv[1],samples,labels))
+    {
+    std::cout<<"Failed to read samples file "<<argv[1]<<std::endl;
+    return EXIT_FAILURE;
+    }
+
+  std::vector<float> priors(26,1.);
+
+
+  RandomForestType::Pointer rfclassifier = RandomForestType::New();
+  rfclassifier->SetInputListSample(samples);
+  rfclassifier->SetTargetListSample(labels);
+
+  //set parameters
+  rfclassifier->SetPriors(priors);
+  // rfclassifier->SetMaxNumberOfTrees(30);
+  // rfclassifier->SetMaxDepth(30);
+  // rfclassifier->SetMaxNumberOfCategories(30);
+  // rfclassifier->SetMaxNumberOfVariables(4);
+
+  rfclassifier->Train();
+
+  rfclassifier->SetTargetListSample(predicted);
+  rfclassifier->PredictAll();
+
+  ConfusionMatrixCalculatorType::Pointer cmCalculator = ConfusionMatrixCalculatorType::New();
+
+  std::cout<<rfclassifier->GetTargetListSample()->Size()<<std::endl;
+
+  cmCalculator->SetProducedLabels(predicted);
+  cmCalculator->SetReferenceLabels(labels);
+  cmCalculator->Update();
+
+  std::cout<<"Confusion matrix: "<<std::endl;
+  std::cout<<cmCalculator->GetConfusionMatrix()<<std::endl;
+  const float kappaIdx = cmCalculator->GetKappaIndex();
+  std::cout<<"Kappa: "<<kappaIdx<<std::endl;
+  std::cout<<"Overall Accuracy: "<<cmCalculator->GetOverallAccuracy()<<std::endl;
+
+  rfclassifier->Save(argv[2]);
+  //std::cout<<"GetTrainError: "<<rfclassifier->GetTrainError() << std::endl;
+
+
+  //Load Model to new RF
+  TargetListSampleType::Pointer predictedLoad = TargetListSampleType::New();
+  RandomForestType::Pointer rfclassifierLoad = RandomForestType::New();
+
+  rfclassifierLoad->Load(argv[2]);
+  rfclassifierLoad->SetInputListSample(samples);
+  rfclassifierLoad->SetTargetListSample(predictedLoad);
+  rfclassifierLoad->PredictAll();
+
+  ConfusionMatrixCalculatorType::Pointer cmCalculatorLoad = ConfusionMatrixCalculatorType::New();
+
+  cmCalculatorLoad->SetProducedLabels(predictedLoad);
+  cmCalculatorLoad->SetReferenceLabels(labels);
+  cmCalculatorLoad->Update();
+
+  std::cout<<"Confusion matrix: "<<std::endl;
+  std::cout<<cmCalculatorLoad->GetConfusionMatrix()<<std::endl;
+  const float kappaIdxLoad = cmCalculatorLoad->GetKappaIndex();
+  std::cout<<"Kappa: "<<kappaIdxLoad<<std::endl;
+  std::cout<<"Overall Accuracy: "<<cmCalculatorLoad->GetOverallAccuracy()<<std::endl;
+
+
+  if ( vcl_abs(kappaIdxLoad - kappaIdx) < 0.00000001)
+    {
+    return EXIT_SUCCESS;
+    }
+  else
+    {
+    return EXIT_FAILURE;
+    }
+}
+
-- 
GitLab