/*
    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 MATRICES_MEASURES_H
#define MATRICES_MEASURES_H

#include "matrices_headers.h"

#include "matrices_all.h"

/// Helper functions operating on CompressedVectors
namespace Measures
{
	using Matrices::CompressedVector;
	using Matrices::CompressedVectorPtr;

	/**
	  Counts Shannon entropy (-Sum p log p).
	  Assumes that values in vectors contains probabilities (p).
	*/
	MATRICES_API double CountVectorEntropy(CompressedVector& v);
	/**
	  Counts Shannon entropy (-Sum p log p).
	  Assumes that values in vectors contains probabilities (p).
	*/
	MATRICES_API double CountVectorEntropy(CompressedVectorPtr v);
	/**
	  Counts sum of vector cells.
	*/
	MATRICES_API double CountVectorSum(CompressedVector& v);
	/**
	  Counts sum of vector cells.
	*/
	MATRICES_API double CountVectorSum(CompressedVectorPtr v);

	/**
	   Counts length of a vector.
	*/
	MATRICES_API double CountVectorLength(CompressedVector &v);

	/**
	   Counts length of a vector.
	*/
	MATRICES_API double CountVectorLength(CompressedVectorPtr v);

	/**
	   Vector normalisation (division of vector values by vector length)
	*/
	MATRICES_API void NormalizeVector(CompressedVector &v);

	/**
	   Vector normalisation (division of vector values by vector length)
	*/
	MATRICES_API void NormalizeVector(CompressedVectorPtr v);

	/**
	 * Divides every vector value by sum of vector values.
	 */
	MATRICES_API void DevideBySum(CompressedVector& v);

	/**
	 * Divides every vector cell by given value.
	 */
	MATRICES_API void DevideByValue(CompressedVector& v, double dev);

	/**
	 * Divides every vector cell by corresponding vector cell in dev vector.
	 */
	MATRICES_API void DevideByValue(CompressedVector& v, const std::vector<double> &dev);

	/**
	 * Divides every vector cell by Shannon entropy of the vector.
	 */
	MATRICES_API void DevideByEntropy(CompressedVector& v);

	/**
	 * Logarithmic scaling of vector cells ( v[i] becomes log(v[i]) )
	 */
	MATRICES_API void TransformByLog(CompressedVector& v);

	/**
	 * "Safe" logarithmic scaling of vector cells ( v[i] becomes log(v[i]+1) )
	 */
	MATRICES_API void TransformByLogPlus1(CompressedVector& v);
	
	/**
	 * Return the maximum value in the vector <i>v</i>
	 * \param CompressedVector& v -- vector
	 * \return double -- maximum value in the vector
	 */
	MATRICES_API double GetMaxValue(CompressedVectorPtr v);	
}

#endif // MATRICES_MEASURES_H
