Jpp  master_rocky-40-g5f0272dcd
the software that should make you happy
Functions
JPolynome5D.cc File Reference

Example program to test multi-dimensional interpolation. More...

#include <string>
#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JTools/JMapList.hh"
#include "JTools/JFunction1D_t.hh"
#include "JTools/JFunctionalMap_t.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JTimer.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

double f5 (const double x0, const double x1, const double x2, const double x3, const double x4)
 5D function. More...
 
int main (int argc, char **argv)
 

Detailed Description

Example program to test multi-dimensional interpolation.

Author
mdejong

Definition in file JPolynome5D.cc.

Function Documentation

◆ f5()

double f5 ( const double  x0,
const double  x1,
const double  x2,
const double  x3,
const double  x4 
)
inline

5D function.

Definition at line 22 of file JPolynome5D.cc.

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 }
const double a
Definition: JQuadrature.cc:42

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 46 of file JPolynome5D.cc.

47 {
48  using namespace std;
49 
50  int numberOfEvents;
51  int numberOfBins;
52  double precision;
53  int debug;
54 
55  try {
56 
57  JParser<> zap("Example program to test multi-dimensional interpolation.");
58 
59  zap['n'] = make_field(numberOfEvents) = 1000;
60  zap['N'] = make_field(numberOfBins) = 11;
61  zap['e'] = make_field(precision) = 1.0e-14;
62  zap['d'] = make_field(debug) = 3;
63 
64  zap(argc, argv);
65  }
66  catch(const exception &error) {
67  FATAL(error.what() << endl);
68  }
69 
70 
71  using namespace JPP;
72 
73 
74  const double xmin = -1.0;
75  const double xmax = +1.0;
76  const double dx = (xmax - xmin) / (numberOfBins - 1);
77 
78 
79  typedef JGridPolint3Function1D_t JFunction1D_t;
80 
84  JPolint3FunctionalGridMap>::maplist JMaplist_t;
85 
86  typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
87 
88 
89  JMultiFunction_t g5;
90 
91 
92  for (double x0 = xmin; x0 <= xmax + 0.5*dx; x0 += dx) {
93  for (double x1 = xmin; x1 <= xmax + 0.5*dx; x1 += dx) {
94  for (double x2 = xmin; x2 <= xmax + 0.5*dx; x2 += dx) {
95  for (double x3 = xmin; x3 <= xmax + 0.5*dx; x3 += dx) {
96  for (double x4 = xmin; x4 <= xmax + 0.5*dx; x4 += dx) {
97  g5[x0][x1][x2][x3][x4] = f5(x0, x1, x2, x3, x4);
98  }
99  }
100  }
101  }
102  }
103 
104  g5.compile();
105  g5.setExceptionHandler(new JFunction1D_t::JDefaultResult(JMATH::zero));
106 
107 
108  ASSERT(numberOfEvents > 0);
109 
110  JTimer timer;
111 
112  JQuantile Q;
113 
114  for (int i = 0; i != numberOfEvents; ++i) {
115 
116  const double x0 = gRandom->Uniform(xmin, xmax);
117  const double x1 = gRandom->Uniform(xmin, xmax);
118  const double x2 = gRandom->Uniform(xmin, xmax);
119  const double x3 = gRandom->Uniform(xmin, xmax);
120  const double x4 = gRandom->Uniform(xmin, xmax);
121 
122  const double v = f5(x0,x1,x2,x3,x4);
123 
124  timer.start();
125 
126  const double w = g5(x0,x1,x2,x3,x4);
127 
128  timer.stop();
129 
130  Q.put(v - w);
131  }
132 
133  if (debug >- debug_t) {
134 
135  Q.print(cout);
136 
137  timer.print(cout, 1.0 / numberOfEvents);
138  }
139 
140  ASSERT(Q.getMean() <= precision);
141  ASSERT(Q.getSTDev() <= precision);
142 
143  return 0;
144 }
#define ASSERT(A,...)
Assert macro.
Definition: JMessage.hh:90
#define FATAL(A)
Definition: JMessage.hh:67
int debug
debug level
Definition: JSirene.cc:69
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition: JParser.hh:2142
double f5(const double x0, const double x1, const double x2, const double x3, const double x4)
5D function.
Definition: JPolynome5D.cc:22
int numberOfBins
number of bins for average CDF integral of optical module
Definition: JSirene.cc:70
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.
const double xmax
Definition: JQuadrature.cc:24
const double xmin
Definition: JQuadrature.cc:23
@ debug_t
debug
Definition: JMessage.hh:29
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).
data_type w[N+1][M+1]
Definition: JPolint.hh:867
data_type v[N+1][M+1]
Definition: JPolint.hh:866
Definition: JSTDTypes.hh:14
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