#ifndef __KLDIVERGENCE__
#define __KLDIVERGENCE__

#include <vector>
#include <math.h>
#include <iostream>
#include <stdlib.h>

class kldivergence
{
 public:
  /// calculate the Jensen-Shannon divergence for samples p and q
  /**
   * @param p samples for P
   * @param q samples for Q
   * @param steps number of bins to use in the range min( min(p), min(q) ) and max( max(p), max(q))
   */
  double calc( std::vector< double > p,
               std::vector< double > q,
               double delta );
 private:
  int genprobs( std::vector<double> &p,
                std::vector<double> &q, double delta );
  int calcprob( std::vector< double > &d, 
                std::vector< double > &pmf );
  std::vector< double > probp, probq, proba;
  double min, max, scale;
  double steps;
};

#endif
