-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
a start to implement #62; requires changes to DNest4
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|