added kernel density wrapper
added general kld solution fixed minor bugs added tests
This commit is contained in:
35
math/distribution/KernelDensity.h
Normal file
35
math/distribution/KernelDensity.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef KERNELDENSITY_H
|
||||
#define KERNELDENSITY_H
|
||||
|
||||
#include <cmath>
|
||||
#include <random>
|
||||
#include <functional>
|
||||
|
||||
#include <eigen3/Eigen/Dense>
|
||||
|
||||
#include "../../Assertions.h"
|
||||
#include "../Random.h"
|
||||
|
||||
|
||||
namespace Distribution {
|
||||
|
||||
template <typename T, typename Sample> class KernelDensity{
|
||||
|
||||
private:
|
||||
const std::function<T(Sample)> probabilityFunction;
|
||||
|
||||
|
||||
public:
|
||||
KernelDensity(const std::function<T(Sample)> probabilityFunction) : probabilityFunction(probabilityFunction){
|
||||
|
||||
}
|
||||
|
||||
T getProbability(Sample sample){
|
||||
return probabilityFunction(sample);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // KERNELDENSITY_H
|
||||
@@ -15,8 +15,8 @@ namespace Distribution {
|
||||
|
||||
private:
|
||||
|
||||
const Eigen::VectorXd mu;
|
||||
const Eigen::MatrixXd sigma;
|
||||
Eigen::VectorXd mu;
|
||||
Eigen::MatrixXd sigma;
|
||||
|
||||
const double _a;
|
||||
const Eigen::MatrixXd _sigmaInv;
|
||||
@@ -61,6 +61,14 @@ namespace Distribution {
|
||||
return this->_sigmaInv;
|
||||
}
|
||||
|
||||
void setSigma(Eigen::MatrixXd sigma){
|
||||
this->sigma = sigma;
|
||||
}
|
||||
|
||||
void setMu(Eigen::VectorXd mu){
|
||||
this->mu = mu;
|
||||
}
|
||||
|
||||
/** return a NormalN based on given data */
|
||||
static NormalDistributionN getNormalNFromSamples(const Eigen::MatrixXd& data) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user