/*
    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 "EvertsMI.h"

namespace smartcomparator
{
	namespace weights
	{
		EvertsMI::EvertsMI(Matrices::SuperMatrixPtr m, double mi_threshold)
			: WeightFeature(m),
			ContingencyTableWeight(m),
			m_dMIThreshold(mi_threshold)
		{
		}// c-tor

		void EvertsMI::Weight(size_t rowindex, Matrices::CompressedVector *v, std::set<size_t> &filteredIndices)
		{

			for(std::set<size_t>::iterator col_iter = filteredIndices.begin(); 
					col_iter != filteredIndices.end(); ++col_iter)
			{
				CountContingencyTableLocal(v, rowindex, *col_iter);
				double mi = log(observed[0][0]/expected[0][0]);
				if(mi > m_dMIThreshold)
					v->SetElement((*col_iter),mi);
			}// for each non-zero column

		}// DoWeight

	}// namespace weights
}// namespace smartcomparator

