Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
wire-cell-build
util
inc
WireCellUtil
Interpolate.h
Go to the documentation of this file.
1
/**
2
Interpolationn helpers.
3
4
See test_interpolate.cxx.
5
*/
6
7
#ifndef WIRECELLUTIL_INTERPOLATE
8
#define WIRECELLUTIL_INTERPOLATE
9
10
#include <vector>
11
12
namespace
WireCell
{
13
14
15
16
/**
17
Use like:
18
19
linterp<double> lin(f.begin(), f.end(), x0, xstep);
20
...
21
double y = lin(42.0);
22
23
where "f" is some kind of collection of doubles.
24
25
*/
26
template
<
class
Real>
27
class
linterp
{
28
public
:
29
template
<
class
B
id
iIterator>
30
linterp
(BidiIterator
f
, BidiIterator end_p, Real left_endpoint, Real
step
)
31
:
m_dat
(f,end_p),
m_le
(left_endpoint),
m_step
(step) {
32
m_re
=
m_le
+
m_step
* (
m_dat
.size()-1);
33
}
34
35
Real
operator()
(Real
x
)
const
{
36
if
(x <=
m_le
)
return
m_dat
.front();
37
if
(x >=
m_re
)
return
m_dat
.back();
38
39
int
ind =
int
((x-
m_le
)/
m_step
);
40
Real y0 =
m_dat
[ind];
41
Real y1 =
m_dat
[ind+1];
42
Real x0 =
m_le
+ ind *
m_step
;
43
44
return
y0 + (x-x0) * (y1-y0) /
m_step
;
45
}
46
47
private
:
48
std::vector<Real>
m_dat
;
49
Real
m_le
,
m_re
,
m_step
;
50
};
51
52
53
54
/** You may also want to use Boost for fancier interpolation.
55
* They have similar calling interface:
56
#include <boost/math/interpolators/cubic_b_spline.hpp>
57
#include <iostream>
58
...
59
boost::math::cubic_b_spline<double> spline(f.begin(), f.end(), x0, xstep);
60
spline(42);
61
*
62
* More info here:
63
https://www.boost.org/doc/libs/1_65_0/libs/math/doc/html/math_toolkit/interpolate/cubic_b.html
64
*/
65
66
67
}
68
69
#endif
WireCell::linterp::operator()
Real operator()(Real x) const
Definition:
Interpolate.h:35
keras_to_tensorflow.f
f
Definition:
keras_to_tensorflow.py:162
WireCell::linterp::linterp
linterp(BidiIterator f, BidiIterator end_p, Real left_endpoint, Real step)
Definition:
Interpolate.h:30
WireCell::linterp::m_step
Real m_step
Definition:
Interpolate.h:49
WireCell::linterp::m_re
Real m_re
Definition:
Interpolate.h:49
keras_to_tensorflow.int
int
Definition:
keras_to_tensorflow.py:69
WireCell::linterp::m_dat
std::vector< Real > m_dat
Definition:
Interpolate.h:48
WireCell
Definition:
Main.h:22
MakeVectorFile.step
tuple step
Definition:
MakeVectorFile.py:59
WireCell::linterp
Definition:
Interpolate.h:27
train.x
list x
Definition:
train.py:276
WireCell::linterp::m_le
Real m_le
Definition:
Interpolate.h:49
Generated by
1.8.11