/** 
* @file VCSVMOneClass.cpp
* @brief One-Class SVM Using C-SVM implementation of T. Joachims (SVM-light)
* @author Erik Rodner + Mi.Ke.
* @date 12/03/2010

*/
#ifdef NICE_USELIB_SVMLIGHT

#include <iostream>

#include "vislearning/classifier/vclassifier/VCSVMOneClass.h"


using namespace OBJREC;

using namespace std;
using namespace NICE;

VCSVMOneClass::VCSVMOneClass ( const Config *_conf, const string & section ) : VecClassifier(_conf) 
{
	svm = new VCSVMLight(_conf,section);
}

VCSVMOneClass::VCSVMOneClass( const VCSVMOneClass& classifier ) : VecClassifier() 
{
	this->svm = classifier.svm;
}

VCSVMOneClass::~VCSVMOneClass()
{
}

ClassificationResult VCSVMOneClass::classify ( const NICE::Vector & x ) const
{
	return svm->classify(x);
}

void VCSVMOneClass::teach ( const LabeledSetVector & _teachSet )
{
	//modify teaching set
	LabeledSetVector lsv;
	LOOP_ALL(_teachSet){
		EACH(classno,vec);
		lsv.add(1,vec);
		lsv.add(0,(-1)*vec);
	}

	svm->teach(lsv);
}

void VCSVMOneClass::finishTeaching()
{
}

/** clone this object */
VCSVMOneClass *VCSVMOneClass::clone(void) const
{
	VCSVMOneClass *classifier = new VCSVMOneClass( *this );
	
	return classifier;
}

void VCSVMOneClass::clear ()
{
	delete svm;
}

void VCSVMOneClass::read (const string& s, int format)
{
	svm->read(s,format);
}

void VCSVMOneClass::save (const string& s, int format) const
{
	svm->save(s,format);
}


void VCSVMOneClass::store ( std::ostream & os, int format ) const
{
	svm->store(os,format);
}

void VCSVMOneClass::restore ( std::istream & is, int format )
{
	svm->restore(is,format);
}


#endif
