/** 
* @file TraceApproximation.h
* @author Erik Rodner
* @date 01/29/2010

*/
#ifndef _NICE_OBJREC_TRACEAPPROXIMATIONINCLUDE
#define _NICE_OBJREC_TRACEAPPROXIMATIONINCLUDE

#include "core/vector/MatrixT.h"
#include "vislearning/math/kernels/KernelData.h"
#include "core/basics/Config.h"

namespace OBJREC {
  
/** @class TraceApproximation
 * approximation of the trace term within the gp regression gradient 
 *
 * @author Erik Rodner
 */
class TraceApproximation
{

    protected:
		int numTraceSamples;
		int displayPoints;

    public:
  
		/** simple constructor */
		TraceApproximation( const NICE::Config *conf, const std::string & section = "TraceApproximation" );
		  
		/** simple destructor */
		virtual ~TraceApproximation();

		/** stochastic approximation of the trace term $tr(K^{-1} jacobiMatrix)$
		 *  as described in "Efficient Implementation of Gaussian Processes ..." */
		double getApproximateTraceTerm ( const KernelData *kernelData, const NICE::Matrix & jacobiMatrix ) const;
    
		/** stochastic approximation of the trace term $tr(K^{-1} A (x) B)$
		 *  as described in "Efficient Implementation of Gaussian Processes ..." */
		double getApproximateTraceTermKronecker ( const KernelData *kernelData, const NICE::Matrix & A, const NICE::Matrix & B ) const;

		double getApproxTraceTermKroneckerPre ( NICE::Matrix & samples, NICE::Matrix & samplesPreMultiplied, const NICE::Matrix & A, const NICE::Matrix & B ) const;

		void preSampling ( const KernelData *kernelData, NICE::Matrix & samples, NICE::Matrix & samplesPreMultiplied ) const;
 
};

}

#endif