Jpp test-rotations-new
the software that should make you happy
Loading...
Searching...
No Matches
JResultHesse3D.cc File Reference

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

#include <iostream>
#include <iomanip>
#include "TRandom3.h"
#include "JMath/JPolynome.hh"
#include "JTools/JElement.hh"
#include "JTools/JGridCollection.hh"
#include "JTools/JGridMap.hh"
#include "JTools/JPolint.hh"
#include "JTools/JMapList.hh"
#include "JTools/JMultiFunction.hh"
#include "JTools/JQuantile.hh"
#include "Jeep/JPrint.hh"
#include "Jeep/JParser.hh"
#include "Jeep/JMessage.hh"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

Example program to test multi-dimensional interpolation.

Author
mdejong

Definition in file JResultHesse3D.cc.

Function Documentation

◆ main()

int main ( int argc,
char ** argv )

Definition at line 53 of file JResultHesse3D.cc.

54{
55 using namespace std;
56 using namespace JPP;
57
58 int numberOfEvents;
59 int numberOfBins;
60 double precision;
61 int debug;
62
63 try {
64
65 JParser<> zap("Example program to test multi-dimensional interpolation.");
66
67 zap['n'] = make_field(numberOfEvents) = 1000;
68 zap['N'] = make_field(numberOfBins) = 11;
69 zap['X'] = make_field(fx) = JPolynome(3, 1.0, 1.0, 1.0);
70 zap['Y'] = make_field(fy) = JPolynome(3, 1.0, 1.0, 1.0);
71 zap['Z'] = make_field(fz) = JPolynome(3, 1.0, 1.0, 1.0);
72 zap['e'] = make_field(precision) = 1.0e-12;
73 zap['d'] = make_field(debug) = 3;
74
75 zap(argc, argv);
76 }
77 catch(const exception &error) {
78 FATAL(error.what() << endl);
79 }
80
81
82 const double xmin = -1.0;
83 const double xmax = +1.0;
84 const double dx = (xmax - xmin) / (numberOfBins - 1);
85
86 typedef JPolintFunction1D<N,
89 JResultHesse<double> > JFunction1D_t;
90 typedef JMAPLIST<JMap_t,
91 JMap_t>::maplist JMaplist_t;
92
93 typedef JMultiFunction<JFunction1D_t, JMaplist_t> JMultiFunction_t;
94 typedef JMultiFunction_t::result_type result_type;
95
96 JMultiFunction_t g3;
97
98
99 for (double x = xmin; x < xmax + 0.5*dx; x += dx) {
100 for (double y = xmin; y < xmax + 0.5*dx; y += dx) {
101 for (double z = xmin; z < xmax + 0.5*dx; z += dx) {
102 g3[x][y][z] = f3(x,y,z);
103 }
104 }
105 }
106
107
108 g3.compile();
109
110
111 if (numberOfEvents > 0) {
112
113 JQuantile Q;
114 JQuantile H[N][N];
115
116 for (int i = 0; i != numberOfEvents; ++i) {
117
118 const double x = gRandom->Uniform(xmin, xmax);
119 const double y = gRandom->Uniform(xmin, xmax);
120 const double z = gRandom->Uniform(xmin, xmax);
121
122 const result_type result = g3(x,y,z);
123
124 const double v = f3(x,y,z);
125 const double w = get_value(result);
126
127 Q.put(v - w);
128
129 H[0][0].put(fx.getDerivative().getDerivative(x) * fy(y) * fz(z) - result.fpp.f.f);
130 H[1][0].put(fx.getDerivative(x) * fy.getDerivative(y) * fz(z) - result.fp.fp.f);
131 H[2][0].put(fx.getDerivative(x) * fy(y) * fz.getDerivative(z) - result.fp.f.fp);
132
133 H[1][1].put(fx(x) * fy.getDerivative().getDerivative(y) * fz(z) - result.f.fpp.f);
134 H[2][1].put(fx(x) * fy.getDerivative(y) * fz.getDerivative(z) - result.f.fp.fp);
135
136 H[2][2].put(fx(x) * fy(y) * fz.getDerivative().getDerivative(z) - result.f.f.fpp);
137 }
138
139 if (debug >= debug_t) {
140
141 Q.print(cout);
142
143 cout << "Hessian matrix" << endl;
144
145 for (int i = 0; i != N; ++i) {
146 for (int j = 0; j <= i; ++j) {
147 cout << ' ' << SCIENTIFIC(12,3) << H[i][j].getMean();
148 }
149 cout << endl;
150 }
151
152 for (int i = 0; i != N; ++i) {
153 for (int j = 0; j <= i; ++j) {
154 cout << ' ' << SCIENTIFIC(12,3) << H[i][j].getSTDev();
155 }
156 cout << endl;
157 }
158 }
159
160 ASSERT(Q.getMean() <= precision);
161 ASSERT(Q.getSTDev() <= precision);
162
163 for (int i = 0; i != N; ++i) {
164 for (int j = 0; j <= i; ++j) {
165 ASSERT(H[i][j].getMean() <= precision);
166 ASSERT(H[i][j].getSTDev() <= precision);
167 }
168 }
169
170 } else {
171
172 for ( ; ; ) {
173
174 cout << "> " << flush;
175
176 string buffer;
177
178 if (getline(cin, buffer) && !buffer.empty()) {
179
180 double x, y, z;
181
182 istringstream(buffer) >> x >> y >> z;
183
184 try {
185 cout << f3(x,y,z) << ' ' << get_value(g3(x,y,z)) << endl;
186 }
187 catch(const JException& exception) {
188 cout << exception << endl;
189 }
190
191 } else {
192 break;
193 }
194 }
195 }
196
197 return 0;
198}
double getMean(vector< double > &v)
get mean of vector content
#define ASSERT(A,...)
Assert macro.
Definition JMessage.hh:90
#define FATAL(A)
Definition JMessage.hh:67
int debug
debug level
Definition JSirene.cc:72
#define make_field(A,...)
macro to convert parameter to JParserTemplateElement object
Definition JParser.hh:2142
double f3(const double x, const double y, const double z)
3D function.
int numberOfBins
number of bins for average CDF integral of optical module
Definition JSirene.cc:73
General exception.
Definition JException.hh:24
Utility class to parse command line options.
Definition JParser.hh:1698
General purpose class for collection of equidistant elements.
Multidimensional interpolation method.
void compile()
Compilation.
Template class for polynomial interpolation in 1D.
Definition JPolint.hh:1095
const double xmax
const double xmin
@ debug_t
debug
Definition JMessage.hh:29
std::istream & getline(std::istream &in, JString &object)
Read string from input stream until end of line.
Definition JString.hh:478
const parameter_list< JPolynome< ID_t, 0 > > JPolynome< ID_t, 0 >::parameters & JPolynome
Set parameters.
Definition JMathlib.hh:1566
static const double H
Planck constant [eV s].
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
return result
Definition JPolint.hh:862
int j
Definition JPolint.hh:801
JResultEvaluator< JResult_t >::result_type get_value(const JResult_t &value)
Helper method to recursively evaluate a to function value.
Definition JResult.hh:998
2D Element.
Definition JPolint.hh:1131
Auxiliary class for recursive map list generation.
Definition JMapList.hh:109
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
Data structure for result including value and first derivative of function.
Definition JResult.hh:215
Auxiliary data structure for floating point format specification.
Definition JManip.hh:488