Skip to content

Commit 17ccd40

Browse files
authored
Merge pull request #3 from Kiguli/test
New Feature: load customCDF via function rather than via file
2 parents 336067f + af60e65 commit 17ccd40

File tree

7 files changed

+642
-680
lines changed

7 files changed

+642
-680
lines changed

examples/ex_customPDF/customPDF.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,36 @@ auto dynamics = [](const vec& x, const vec& u) -> vec {
4545
return xx;
4646
};
4747

48+
/// Custom PDF function, change this to the PDF function desired that will be integrated over with Monte Carlo integration
49+
double customPDF(double *x, size_t dim, void *params){
50+
//custom PDF parameters that are passed in (not all need to be used)
51+
customParams *p = reinterpret_cast<customParams*>(params);
52+
vec mean = p-> mean;
53+
vec state_start = p->state_start;
54+
function<vec(const vec&,const vec&)> dynamics2 = p-> dynamics2;
55+
vec input = p-> input;
56+
vec lb = p-> lb;
57+
vec ub = p-> ub;
58+
vec eta = p-> eta;
59+
/* Other parameters of struct unused in the ex_custom_distribution example:*/
60+
//function<vec(const vec&)> dynamics1 = p->dynamics1;
61+
//function<vec(const vec&,const vec&)> dynamics3 = p-> dynamics3;
62+
//vec disturb = p-> disturb;
63+
64+
//multivariate normal PDF example:
65+
double cov_det = 0.5625;
66+
mat inv_cov = {{1.3333, 0},{0, 1.3333}};
67+
double norm = 1.0 / (pow(2 * M_PI, dim / 2.0) * sqrt(cov_det));
68+
69+
double exponent = 0.0;
70+
for (size_t i = 0; i < dim; ++i) {
71+
for (size_t j = 0; j < dim; ++j) {
72+
exponent -= 0.5 * (x[i] - mean[i]) * (x[j] - mean[j]) * inv_cov(i,j);
73+
}
74+
}
75+
return norm * exp(exponent);
76+
};
77+
4878
/*
4979
################################# MAIN FUNCTION ##############################################
5080
*/
@@ -69,7 +99,7 @@ int main() {
6999
/*###### set dynamics and noise ######*/
70100
mdp.setDynamics(dynamics);
71101
mdp.setNoise(NoiseType::CUSTOM);
72-
mdp.setCustomDistribution(1000);
102+
mdp.setCustomDistribution(customPDF,1000); //note this is updated from the original IMPaCT release
73103

74104
/* ###### calculate abstraction for target vectors ######*/
75105
mdp.targetTransitionVectorBounds();

src/GPU_synthesis.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include <string>
77
#include <nlopt.hpp>
88
#include <iomanip>
9-
#include <sycl/sycl.hpp>
9+
#include <AdaptiveCpp/sycl/sycl.hpp>
1010
#include <chrono>
1111
#include <armadillo>
12-
#include <hdf5.h>
12+
#include <hdf5/serial/hdf5.h>
1313

1414
using namespace std;
1515
using namespace arma;

0 commit comments

Comments
 (0)