/***************************************************************************
                          Evaluation.cpp  -  description
                             -------------------
    begin                : Mit Feb 23 2005
    copyright            : (C) 2005 by klaus frieler
    email                : kgf@omniversum.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "Evaluation.h"

MRESULT Evaluation::evaluate(const Vector& data)
{
   m_iTP = m_iTN = m_iFP = m_iFN = 0; 
   if(data.size() != size()){
      return ERR_INVALIDARG;
   }
   m_diff = m_groundTruth-data;
   for(uint i = 0; i<m_diff.size(); ++i){
      if(m_diff[i] == 0){
         if(m_groundTruth[i] == 0) m_iTN++;
         else m_iTP++;
      }
      if(m_diff[i]<0)
         m_iFP++;
      if(m_diff[i]>0)
         m_iFN++;     
   }
   m_dSensitivity = (m_iFN+m_iTP!= 0) ? (m_iTP+.0)/(m_iFN+m_iTP): 0;
   m_dSpecificity = (m_iFP+m_iTN != 0) ? (m_iTN+.0)/(m_iFP+m_iTN):0;
   return SUCC_OK;
}

void Evaluation::dump()const
{
   //m_diff.dump("Difference\n");
   
   cout<<"TP = "<<m_iTP<<" TN = "<<m_iTN<<" FP = "<<m_iFP<<" FN = "<<m_iFN<<endl;
   cout<<"Sensitivity = "<<m_dSensitivity<<" Specificity= "<<m_dSpecificity<<endl;
}