/*
    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.
*/

#ifndef SMARTCOMPARATOR_CONTINGENCY_TABLE_WEIGHT_H
#define SMARTCOMPARATOR_CONTINGENCY_TABLE_WEIGHT_H
#include "../comparator_stdheaders.h"
#include "WeightFeature.h"

namespace smartcomparator
{
	namespace weights
	{
		class SMART_COMPARATOR_API ContingencyTableWeight 
		{
		public:
			ContingencyTableWeight(Matrices::SuperMatrixPtr m);

		protected:
			void CountContingencyTableLocal(Matrices::CompressedVector *row, size_t row_index, size_t column_index);
			void CountContingencyTableGlobal(Matrices::CompressedVector *row, size_t row_index, size_t column_index);

			// those values will be set after calling CountContingencyTable* funcions
			double R1,R2,C1,C2,N;
			double observed[2][2];
			double expected[2][2];

		private:
			/**
			 * This method initializes m_vRowSums, and m_stFilteredMatrixSum
			 */ 
			void CountRowSums();

			std::vector<double> m_vRowSums;
			double m_stFilteredMatrixSum;
			Matrices::SuperMatrixPtr m_pMatrix;
		};

	} // namespace weights

}// namespace smartcomparator

#endif // SMARTCOMPARATOR_CONTINGENCY_TABLE_WEIGHT_H


