GooseEYE 0.9.1
Loading...
Searching...
No Matches
Ensemble.hpp
Go to the documentation of this file.
1
7#ifndef GOOSEEYE_ENSEMBLE_HPP
8#define GOOSEEYE_ENSEMBLE_HPP
9
10#include "GooseEYE.h"
11
12namespace GooseEYE {
13
14inline Ensemble::Ensemble(const std::vector<size_t>& roi, bool periodic, bool variance)
15 : m_periodic(periodic), m_variance(variance), m_shape_orig(roi)
16{
17 GOOSEEYE_ASSERT(m_shape_orig.size() <= MAX_DIM, std::out_of_range);
18
19 m_first = xt::atleast_3d(xt::zeros<double>(m_shape_orig));
20 m_second = zeros_like(m_first);
21 m_norm = zeros_like(m_first);
22 m_shape = std::vector<size_t>(m_first.shape().begin(), m_first.shape().end());
23 m_pad = detail::pad_width(m_shape);
24}
25
27{
28 array_type::array<double> ret = m_first / xt::where(m_norm <= 0, 1.0, m_norm);
29
30 if (m_stat == Type::heightheight) {
31 ret = xt::pow(ret, 0.5);
32 }
33
34 return ret.reshape(m_shape_orig);
35}
36
38{
39 array_type::tensor<double, 3> norm = xt::where(m_norm <= 0, 1.0, m_norm);
41 (m_second / norm - xt::pow(m_first / norm, 2.0)) * norm / (norm - 1);
42
43 if (m_stat == Type::heightheight) {
44 ret = xt::pow(ret, 0.5);
45 }
46 else if (m_stat != Type::mean) {
47 throw std::runtime_error("Not implemented");
48 }
49
50 return ret.reshape(m_shape_orig);
51}
52
54{
55 array_type::array<double> ret = m_first;
56 return ret.reshape(m_shape_orig);
57}
58
60{
61 array_type::array<double> ret = m_second;
62 return ret.reshape(m_shape_orig);
63}
64
66{
67 array_type::array<double> ret = m_norm;
68 return ret.reshape(m_shape_orig);
69}
70
72{
73 GOOSEEYE_ASSERT(axis < m_shape_orig.size(), std::out_of_range);
74 axis = detail::atleast_3d_axis(m_shape_orig.size(), axis);
75
76 array_type::tensor<double, 3> dist = xt::empty<double>(m_shape);
77
78 array_type::array<double> D = xt::linspace<double>(
79 -1.0 * static_cast<double>(m_pad[axis][0]),
80 static_cast<double>(m_pad[axis][1]),
81 m_shape[axis]);
82
83 for (size_t h = 0; h < m_shape[0]; ++h) {
84 for (size_t i = 0; i < m_shape[1]; ++i) {
85 for (size_t j = 0; j < m_shape[2]; ++j) {
86 if (axis == 0) {
87 dist(h, i, j) = D(h);
88 }
89 else if (axis == 1) {
90 dist(h, i, j) = D(i);
91 }
92 else if (axis == 2) {
93 dist(h, i, j) = D(j);
94 }
95 }
96 }
97 }
98
99 array_type::array<double> ret = std::move(dist);
100 return ret.reshape(m_shape_orig);
101}
102
104{
105 array_type::array<double> ret = xt::zeros<double>(m_shape_orig);
106
107 for (size_t i = 0; i < m_shape_orig.size(); ++i) {
108 ret += xt::pow(this->distance(i), 2.0);
109 }
110
111 return xt::pow(ret, 0.5);
112}
113
114inline array_type::array<double> Ensemble::distance(const std::vector<double>& h) const
115{
116 GOOSEEYE_ASSERT(m_shape_orig.size() == h.size(), std::out_of_range);
117
118 array_type::array<double> ret = xt::zeros<double>(m_shape_orig);
119
120 for (size_t i = 0; i < m_shape_orig.size(); ++i) {
121 ret += xt::pow(this->distance(i) * h[i], 2.0);
122 }
123
124 return xt::pow(ret, 0.5);
125}
126
127inline array_type::array<double> Ensemble::distance(const std::vector<double>& h, size_t axis) const
128{
129 GOOSEEYE_ASSERT(m_shape_orig.size() == h.size(), std::out_of_range);
130 return this->distance(axis) * h[axis];
131}
132
133} // namespace GooseEYE
134
135#endif
array_type::array< double > data_second() const
Get raw-data: ensemble sum of the second moment: x_1^2 + x_2^2 + ...
Definition Ensemble.hpp:59
Ensemble()=default
Constructor.
array_type::array< double > variance() const
Get ensemble variance.
Definition Ensemble.hpp:37
array_type::array< double > data_first() const
Get raw-data: ensemble sum of the first moment: x_1 + x_2 + ...
Definition Ensemble.hpp:53
array_type::array< double > distance() const
Get the relative distance of each pixel in the 'region-of-interest' to its center.
Definition Ensemble.hpp:103
array_type::array< double > result() const
Get ensemble average.
Definition Ensemble.hpp:26
array_type::array< double > norm() const
Get raw-data: normalisation (number of measurements per pixel).
Definition Ensemble.hpp:65
#define GOOSEEYE_ASSERT(expr, assertion)
All assertions are implemented as:
Definition config.h:91
xt::xtensor< T, N > tensor
Fixed (static) rank array.
Definition config.h:155
Toolbox to compute statistics.
Definition config.h:128