Jpp 19.3.0-rc.5
the software that should make you happy
Loading...
Searching...
No Matches
JPolynome5D.cc
Go to the documentation of this file.
1
2#include <string>
3#include <iostream>
4#include <iomanip>
5
6#include "TRandom3.h"
7
8#include "JTools/JMapList.hh"
12#include "JTools/JQuantile.hh"
13
14#include "Jeep/JTimer.hh"
15#include "Jeep/JParser.hh"
16#include "Jeep/JMessage.hh"
17
18
19/**
20 * 5D function.
21 */
22inline double f5(const double x0,
23 const double x1,
24 const double x2,
25 const double x3,
26 const double x4)
27{
28 static const double a = 1.0;
29 static const double b = 1.0;
30 static const double c = 1.0;
31
32 return
33 x0 * (a + x0 * (b + c*x0)) *
34 x1 * (a + x1 * (b + c*x1)) *
35 x2 * (a + x2 * (b + c*x2)) *
36 x3 * (a + x3 * (b + c*x3)) *
37 x4 * (a + x4 * (b + c*x4));
38}
39
40
41/**
42 * \file
43 * Example program to test multi-dimensional interpolation.
44 * \author mdejong
45 */
46int main(int argc, char **argv)
47{
48 using namespace std;
49 using namespace JPP;
50
51 int numberOfEvents;
52 int numberOfBins;
53 double precision;
54 int debug;
55
56 try {
57
58 JParser<> zap("Example program to test multi-dimensional interpolation.");
59
60 zap['n'] = make_field(numberOfEvents) = 1000;
61 zap['N'] = make_field(numberOfBins) = 11;
62 zap['e'] = make_field(precision) = 1.0e-14;
63 zap['d'] = make_field(debug) = 3;
64
65 zap(argc, argv);
66 }
67 catch(const exception &error) {
68 FATAL(error.what() << endl);
69 }
70
71
72 const double xmin = -1.0;
73 const double xmax = +1.0;
74 const double dx = (xmax - xmin) / (numberOfBins - 1);
75
76
77 typedef JGridPolint3Function1D_t JFunction1D_t;
78
82 JPolint3FunctionalGridMap>::maplist JMaplist_t;
83
84 typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
85
86
87 JMultiFunction_t g5;
88
89
90 for (double x0 = xmin; x0 <= xmax + 0.5*dx; x0 += dx) {
91 for (double x1 = xmin; x1 <= xmax + 0.5*dx; x1 += dx) {
92 for (double x2 = xmin; x2 <= xmax + 0.5*dx; x2 += dx) {
93 for (double x3 = xmin; x3 <= xmax + 0.5*dx; x3 += dx) {
94 for (double x4 = xmin; x4 <= xmax + 0.5*dx; x4 += dx) {
95 g5[x0][x1][x2][x3][x4] = f5(x0, x1, x2, x3, x4);
96 }
97 }
98 }
99 }
100 }
101
102 g5.compile();
103 g5.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
104
105 ASSERT(numberOfEvents > 0);
106
107 {
108 const double x = xmin - dx;
109
110 ASSERT(fabs(g5(x, 0.0, 0.0, 0.0, 0.0)) <= precision);
111 ASSERT(fabs(g5(0.0, x, 0.0, 0.0, 0.0)) <= precision);
112 ASSERT(fabs(g5(0.0, 0.0, x, 0.0, 0.0)) <= precision);
113 ASSERT(fabs(g5(0.0, 0.0, 0.0, x, 0.0)) <= precision);
114 ASSERT(fabs(g5(0.0, 0.0, 0.0, 0.0, x)) <= precision);
115 }
116
117 JTimer timer;
118
119 JQuantile Q;
120
121 for (int i = 0; i != numberOfEvents; ++i) {
122
123 const double x0 = gRandom->Uniform(xmin, xmax);
124 const double x1 = gRandom->Uniform(xmin, xmax);
125 const double x2 = gRandom->Uniform(xmin, xmax);
126 const double x3 = gRandom->Uniform(xmin, xmax);
127 const double x4 = gRandom->Uniform(xmin, xmax);
128
129 const double v = f5(x0,x1,x2,x3,x4);
130
131 timer.start();
132
133 const double w = g5(x0,x1,x2,x3,x4);
134
135 timer.stop();
136
137 Q.put(v - w);
138 }
139
140 if (debug >- debug_t) {
141
142 Q.print(cout);
143
144 timer.print(cout, 1.0 / numberOfEvents);
145 }
146
147 ASSERT(Q.getMean() <= precision);
148 ASSERT(Q.getSTDev() <= precision);
149
150 return 0;
151}
Various implementations of functional maps.
General purpose messaging.
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
Utility class to parse command line options.
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
int main(int argc, char **argv)
double f5(const double x0, const double x1, const double x2, const double x3, const double x4)
5D function.
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
Auxiliary class for CPU timing and usage.
Definition JTimer.hh:33
void print(std::ostream &out, const JScale_t scale=milli_t) const
Print timer data.
Definition JTimer.hh:172
void stop()
Stop timer.
Definition JTimer.hh:127
void start()
Start timer.
Definition JTimer.hh:106
Utility class to parse command line options.
Definition JParser.hh:1698
Multidimensional interpolation method.
void compile()
Compilation.
static const JZero zero
Function object to assign zero value.
Definition JZero.hh:105
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Type definition of a 3rd degree polynomial interpolation based on a JGridCollection with result type ...
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
Type definition of a 3rd degree polynomial interpolation based on a JGridMap implementation.
Auxiliary data structure for running average, standard deviation and quantiles.
Definition JQuantile.hh:46
std::ostream & print(std::ostream &out, bool lpr=true) const
Print quantile.
Definition JQuantile.hh:382
double getSTDev() const
Get standard deviation.
Definition JQuantile.hh:281
void put(const double x, const double w=1.0)
Put value.
Definition JQuantile.hh:133
double getMean() const
Get mean value.
Definition JQuantile.hh:252