Skip to content

Commit

Permalink
a start to implement #62; requires changes to DNest4
Browse files Browse the repository at this point in the history
  • Loading branch information
j-faria committed May 12, 2020
1 parent 933be3b commit 1868ca6
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/distributions/mixGaussianLogUniform.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "mixGaussianLogUniform.h"

namespace DNest4
{

/**
* Construct an mixGaussianLogUniform distribution
*/
mixGaussianLogUniform::mixGaussianLogUniform(double mean, double sigma, double lower, double upper)
{
G = Gaussian(mean, sigma);
LU = LogUniform(lower, upper);
}


/* mixGaussianLogUniform distribution function */
double mixGaussianLogUniform::cdf(double x) const
{
return 0.5 * G.cdf(x) + 0.5 * LU.cdf(x);
}

/* Quantile estimate, midpoint interpolation */
double mixGaussianLogUniform::cdf_inverse(double p) const
{
// not implemented
throw std::runtime_error("cdf_inverse not implemented for `mixGaussianLogUniform`");
}

double mixGaussianLogUniform::log_pdf(double x) const
{
return 0.5 * G.log_pdf(x) + 0.5 * LU.log_pdf(x);
}

double mixGaussianLogUniform::perturb(double& x, RNG& rng) const
{
x = cdf(x);
x += rng.randh();
wrap(x, 0.0, 1.0);
if (rng.rand_int(2) == 0)
x = G.cdf_inverse(x);
else
x = LU.cdf_inverse(x);
return 0.0;
}


} // namespace DNest4

36 changes: 36 additions & 0 deletions src/distributions/mixGaussianLogUniform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#pragma once

// DNest4/code
#include "DNest4.h"
#include <limits>
#include <stdlib.h>
#include <stdint.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>

using namespace std;

namespace DNest4
{

class mixGaussianLogUniform:public ContinuousDistribution
{
private:
DNest4::Gaussian G;
DNest4::LogUniform LU;

public:
mixGaussianLogUniform(double mean=0.0, double sigma=1.0, double lower=1.0, double upper=2.0);

double cdf(double x) const;
double cdf_inverse(double p) const;
double log_pdf(double x) const;
double perturb(double& x, RNG& rng) const override;
};


} // namespace DNest4

0 comments on commit 1868ca6

Please sign in to comment.