/*
    Copyright (C) 2012 Bartosz Broda, Jacek Bochenek, Łukasz Biłeńkij, 
    Damian Jaworski, Wojciech Mazur, Dominik Piasecki, Maciej Piasecki, 
    Radosław Ramocki
    
    This program is free software; you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your option)
any later version.

    This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE. 

    See the LICENSE and COPYING files for more details.
*/

#include "../comparator_stdheaders.h"
#include "EhlertSimilarity.h"

namespace smartcomparator
{
namespace simfunctions
{
	EhlertSimilarity::EhlertSimilarity(Matrices::SuperMatrixPtr m, double d, double g, double a) 
		: SimilarityFunction(m), delta(d), gamma(g), alpha(a)
	{
	}

	EhlertSimilarity::~EhlertSimilarity(void)
	{
	}

	double EhlertSimilarity::CountSimilarity(Matrices::CompressedVector& v1, Matrices::CompressedVector& v2,
			size_t v1ind, size_t v2ind,  const std::set<size_t> &filteredIndices)
	{
		double divergence = 0;

		for(std::set<size_t>::const_iterator i = filteredIndices.begin(); i != filteredIndices.end(); i++)
		{
			double c = 1;
			double p = (v1)[*i];
			double q = (v2)[*i];

			divergence += pow(c, -alpha) * pow(p, delta) * pow(q, gamma);

		}

		return DivergenceToSim(1 - divergence);
	}

	double EhlertSimilarity::DivergenceToSim(double div)
	{
		return div;
	}
}
}
