/** 
 * @file VCTransform.cpp
 // refactor-nice.pl: check this substitution
 // old: * @brief Vector Transform
 * @brief NICE::Vector Transform
 * @author Michael Koch
 * @date 11/28/2007

 */
#include <iostream>
#include <fstream>

#include "vislearning/classifier/vclassifier/VCTransform.h"
#include "core/basics/FileMgt.h"
#include "vislearning/math/ftransform/PCA.h"

using namespace OBJREC;

using namespace std;
// refactor-nice.pl: check this substitution
// old: using namespace ice;
using namespace NICE;

VCTransform::VCTransform(const Config *conf, VecClassifier * classifier,
		FTransform * transform)
{
	this->classifier = classifier;
	this->transform = transform;
	this->dimension = conf->gI("FTransform", "dimension", 10);
	this->mode = conf->gI("FTransform", "mode", 0);
	transformedSet.clear();
}

VCTransform::~VCTransform()
{
}

/** classify using simple vector */
ClassificationResult VCTransform::classify(const NICE::Vector & x) const
{
	NICE::Vector transformed_vector = transform->getFeatureVector(x);
	cerr << "PCA: transformed-vector: " << transformed_vector << endl;
	return this->classifier->classify(transformed_vector);
}

void VCTransform::teach(const LabeledSetVector & teachSet)
{
	maxClassNo = teachSet.getMaxClassno();

	int n = teachSet.count();
	int d = teachSet.dimension();
	NICE::Matrix X = Matrix(n, d);
	//get input data
	uint featurecount = 0;
	LOOP_ALL(teachSet)
		{
			EACH(classno,x);
			for (uint k = 0; k < x.size(); ++k)
			{
				X(featurecount, k) = x[k];

			}

			++featurecount;
		}

	//learning Ftransform
	transform->calculateBasis(X, this->dimension, this->mode);

	//save transformed Vectors
	LOOP_ALL(teachSet)
		{
			EACH(classno,x);
			NICE::Vector transformed_vector = transform->getFeatureVector(x);
			cerr << "PCA: transformed-vector: " << transformed_vector << endl;
			transformedSet.add(classno, transformed_vector);

		}
	this->classifier->teach(transformedSet);

}
void VCTransform::finishTeaching()
{
	this->classifier->finishTeaching();
}

void VCTransform::restore(std::istream & is, int format)
{
	fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
	exit(-1);
}

void VCTransform::store(std::ostream & is, int format) const
{
	fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
	exit(-1);
}

void VCTransform::clear()
{
	fprintf(stderr, "NOT YET IMPLEMENTED !!\n");
	exit(-1);
}

