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

namespace smartcomparator
{
	namespace weights
	{
		CTBasedWeight::CTBasedWeight(
			Matrices::SuperMatrixPtr pMtx,
			double pThreshold)
		:
			WeightFeature(pMtx),
			ContingencyTableWeight(pMtx),
			mThreshold(pThreshold)
		{
		}


		CTBasedWeight::~CTBasedWeight(){

		}


		void CTBasedWeight::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 value = countValue(
					observed[0][0],
					observed[0][1],
					observed[1][0],
					observed[1][1],
					N);
				v->SetElement((*col_iter), value <= mThreshold ? 0.0 : value);
			}
		}


		double CTBasedWeight::getThreshold() const {
			return mThreshold;
		}

	}// namespace weights
}// namespace smartcomparator

