44 #ifndef ROL_DISTRIBUTION_HPP 45 #define ROL_DISTRIBUTION_HPP 60 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
61 ">>> ERROR (ROL::Distribution): evaluatePDF not implemented!");
66 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
67 ">>> ERROR (ROL::Distribution): evaluateCDF not implemented!");
72 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
73 ">>> ERROR (ROL::Distribution): integrateCDF not implemented!");
78 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
79 ">>> ERROR (ROL::Distribution): invertCDF not implemented!");
83 virtual Real
moment(
const size_t m)
const {
84 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
85 ">>> ERROR (ROL::Distribution): moment not implemented!");
89 virtual void test(std::ostream &outStream = std::cout)
const {
90 TEUCHOS_TEST_FOR_EXCEPTION(
true, std::invalid_argument,
91 ">>> ERROR (ROL::Distribution): test not implemented!");
95 void test(
const std::vector<Real> &X,
const std::vector<int> &T,
96 std::ostream &outStream = std::cout )
const {
97 size_t size = X.size();
98 for (
size_t k = 0; k < size; k++ ) {
111 void test_onesided(
const Real x, std::ostream &outStream = std::cout)
const {
112 Real X = x, vx = 0., vy = 0., dv = 0., t = 1., diff = 0., err = 0.;
120 outStream << std::scientific << std::setprecision(11);
121 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = cdf(x) with x = " 122 << X <<
" is correct?" << std::endl;
123 outStream << std::right << std::setw(20) <<
"t" 124 << std::setw(20) <<
"f'(x)" 125 << std::setw(20) <<
"(f(x+t)-f(x))/t" 126 << std::setw(20) <<
"Error" 128 for (
int i = 0; i < 13; i++) {
131 err = std::abs(diff-dv);
132 outStream << std::scientific << std::setprecision(11) << std::right
133 << std::setw(20) << t
134 << std::setw(20) << dv
135 << std::setw(20) << diff
136 << std::setw(20) << err
140 outStream << std::endl;
142 catch(std::exception &e) {
143 outStream <<
"Either evaluateCDF or evaluatePDF is not implemented!" 144 << std::endl << std::endl;
154 outStream << std::scientific << std::setprecision(11);
155 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = intcdf(x) with x = " 156 << X <<
" is correct?" << std::endl;
157 outStream << std::right << std::setw(20) <<
"t" 158 << std::setw(20) <<
"f'(x)" 159 << std::setw(20) <<
"(f(x+t)-f(x))/t" 160 << std::setw(20) <<
"Error" 162 for (
int i = 0; i < 13; i++) {
165 err = std::abs(diff-dv);
166 outStream << std::scientific << std::setprecision(11) << std::right
167 << std::setw(20) << t
168 << std::setw(20) << dv
169 << std::setw(20) << diff
170 << std::setw(20) << err
174 outStream << std::endl;
176 catch(std::exception &e) {
177 outStream <<
"Either evaluateCDF or integrateCDF is not implemented!" 178 << std::endl << std::endl;
184 err = std::abs(x-vy);
185 outStream << std::scientific << std::setprecision(11);
186 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = invcdf(x) with x = " 187 << X <<
" is correct?" << std::endl;
188 outStream << std::right << std::setw(20) <<
"cdf(x)" 189 << std::setw(20) <<
"invcdf(cdf(x))" 190 << std::setw(20) <<
"Error" 192 outStream << std::scientific << std::setprecision(11) << std::right
193 << std::setw(20) << vx
194 << std::setw(20) << vy
195 << std::setw(20) << err
196 << std::endl << std::endl;
198 catch(std::exception &e) {
199 outStream <<
"Either evaluateCDF or invertCDF is not implemented!" 200 << std::endl << std::endl;
204 void test_centered(
const Real x, std::ostream &outStream = std::cout)
const {
205 Real X = x, vx = 0., vy = 0., dv = 0., t = 1., diff = 0., err = 0.;
213 outStream << std::scientific << std::setprecision(11);
214 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = cdf(x) with x = " 215 << X <<
" is correct?" << std::endl;
216 outStream << std::right << std::setw(20) <<
"t" 217 << std::setw(20) <<
"f'(x)" 218 << std::setw(20) <<
"(f(x+t)-f(x-t))/2t" 219 << std::setw(20) <<
"Error" 221 for (
int i = 0; i < 13; i++) {
224 diff = 0.5*(vx-vy)/t;
225 err = std::abs(diff-dv);
226 outStream << std::scientific << std::setprecision(11) << std::right
227 << std::setw(20) << t
228 << std::setw(20) << dv
229 << std::setw(20) << diff
230 << std::setw(20) << err
236 catch(std::exception &e) {
237 outStream <<
"Either evaluateCDF or evaluatePDF is not implemented!" 238 << std::endl << std::endl;
248 outStream << std::scientific << std::setprecision(11);
249 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = intcdf(x) with x = " 250 << X <<
" is correct?" << std::endl;
251 outStream << std::right << std::setw(20) <<
"t" 252 << std::setw(20) <<
"f'(x)" 253 << std::setw(20) <<
"(f(x+t)-f(x-t))/2t" 254 << std::setw(20) <<
"Error" 256 for (
int i = 0; i < 13; i++) {
259 diff = 0.5*(vx-vy)/t;
260 err = std::abs(diff-dv);
261 outStream << std::scientific << std::setprecision(11) << std::right
262 << std::setw(20) << t
263 << std::setw(20) << dv
264 << std::setw(20) << diff
265 << std::setw(20) << err
269 outStream << std::endl;
271 catch(std::exception &e) {
272 outStream <<
"Either evaluateCDF or integrateCDF is not implemented!" 273 << std::endl << std::endl;
279 err = std::abs(X-vy);
280 outStream << std::scientific << std::setprecision(11);
281 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: f(x) = invcdf(x) with x = " 282 << X <<
" is correct?" << std::endl;
283 outStream << std::right << std::setw(20) <<
"cdf(x)" 284 << std::setw(20) <<
"invcdf(cdf(x))" 285 << std::setw(20) <<
"Error" 287 outStream << std::scientific << std::setprecision(11) << std::right
288 << std::setw(20) << vx
289 << std::setw(20) << vy
290 << std::setw(20) << err
291 << std::endl << std::endl;
293 catch(std::exception &e) {
294 outStream <<
"Either evaluateCDF or invertCDF is not implemented!" 295 << std::endl << std::endl;
299 void test_moment(
const size_t order, std::ostream &outStream = std::cout)
const {
301 const size_t numPts = 10000;
302 Real pt = 0., wt = 1./(Real)numPts;
303 std::vector<Real> mVec(order,0.);
304 for (
size_t i = 0; i < numPts; i++) {
305 pt =
invertCDF((Real)rand()/(Real)RAND_MAX);
307 for (
size_t q = 1; q < order; q++) {
308 mVec[q] += wt*std::pow(pt,q+1);
311 outStream << std::scientific << std::setprecision(0);
312 outStream << std::right << std::setw(20) <<
"CHECK DENSITY: Check first " << order
313 <<
" moments against Monte Carlo using " << numPts <<
" samples" 315 outStream << std::setw(20) <<
"Error should be O(" << 1./std::sqrt(numPts) <<
")" << std::endl;
316 outStream << std::scientific << std::setprecision(11);
317 for (
size_t q = 0; q < order; q++) {
318 outStream << std::setw(20) <<
"Error in " << q+1 <<
" moment: " 319 << std::abs(mVec[q]-
moment(q+1)) << std::endl;
321 outStream << std::endl;
323 catch(std::exception &e) {
324 outStream <<
"moment is not implemented!" 325 << std::endl << std::endl;
void test_moment(const size_t order, std::ostream &outStream=std::cout) const
void test_centered(const Real x, std::ostream &outStream=std::cout) const
virtual Real evaluatePDF(const Real input) const
Contains definitions of custom data types in ROL.
virtual Real integrateCDF(const Real input) const
virtual ~Distribution(void)
virtual Real invertCDF(const Real input) const
void test_onesided(const Real x, std::ostream &outStream=std::cout) const
virtual void test(std::ostream &outStream=std::cout) const
virtual Real evaluateCDF(const Real input) const
void test(const std::vector< Real > &X, const std::vector< int > &T, std::ostream &outStream=std::cout) const
virtual Real moment(const size_t m) const