Jpp 20.0.0-27-g39925593c-D
the software that should make you happy
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | List of all members
JASTRONOMY::JGarage< T, factor > Struct Template Reference

Auxiliary container for statistical analysis of a large number of positive (or zero) values. More...

#include <JGarage.hh>

Inheritance diagram for JASTRONOMY::JGarage< T, factor >:
std::vector< std::vector< T > >

Public Types

typedef std::vector< std::vector< T > > map_type
 
typedef map_type::value_type value_type
 
typedef map_type::const_iterator const_iterator
 
typedef map_type::const_reverse_iterator const_reverse_iterator
 

Public Member Functions

size_t getN () const
 Get total number of values.
 
getMin () const
 Get minimal value.
 
getMax () const
 Get maximal value.
 
void put (const T value)
 Add value to container.
 
template<class JFunction_t >
void put (const size_t N, const JFunction_t &object)
 Add values to container.
 
template<class JFunction_t >
void operator() (const JFunction_t &object) const
 For-each method.
 
getValue (const double P) const
 Get minimal value corresponding given maximal probability.
 
double getProbability (const T value) const
 Get maximal probability corresponding given minimal value.
 

Static Public Member Functions

static size_t getKey (const T value)
 Get hash key corresponding to given value.
 

Detailed Description

template<class T, const size_t factor = 0>
struct JASTRONOMY::JGarage< T, factor >

Auxiliary container for statistical analysis of a large number of positive (or zero) values.

The data are organised in groups according to a numerical hash key so that the computation involving quantiles can be made faster.
The numerical hash key is obtained by multiplying the input value with the given factor and then taking the unsigned integer value of the result.
The computed quantiles correspond to a distribution with ascending values.

Definition at line 28 of file JGarage.hh.

Member Typedef Documentation

◆ map_type

template<class T , const size_t factor = 0>
typedef std::vector< std::vector<T> > JASTRONOMY::JGarage< T, factor >::map_type

Definition at line 31 of file JGarage.hh.

◆ value_type

template<class T , const size_t factor = 0>
typedef map_type::value_type JASTRONOMY::JGarage< T, factor >::value_type

Definition at line 32 of file JGarage.hh.

◆ const_iterator

template<class T , const size_t factor = 0>
typedef map_type::const_iterator JASTRONOMY::JGarage< T, factor >::const_iterator

Definition at line 33 of file JGarage.hh.

◆ const_reverse_iterator

template<class T , const size_t factor = 0>
typedef map_type::const_reverse_iterator JASTRONOMY::JGarage< T, factor >::const_reverse_iterator

Definition at line 34 of file JGarage.hh.

Member Function Documentation

◆ getN()

template<class T , const size_t factor = 0>
size_t JASTRONOMY::JGarage< T, factor >::getN ( ) const
inline

Get total number of values.

Returns
number of values

Definition at line 42 of file JGarage.hh.

43 {
44 using namespace std;
45
46 return accumulate(this->begin(), this->end(), 0, [](const size_t n, const value_type& buffer) { return n + buffer.size(); });
47 }
void accumulate(T &value, JBool< false > option)
Accumulation of value.
const int n
Definition JPolint.hh:791

◆ getMin()

template<class T , const size_t factor = 0>
T JASTRONOMY::JGarage< T, factor >::getMin ( ) const
inline

Get minimal value.

Returns
value

Definition at line 55 of file JGarage.hh.

56 {
57 using namespace std;
58
59 for (const_iterator i = this->begin(); i != this->end(); ++i) {
60 if (!i->empty()) {
61 return *min_element(i->begin(), i->end());
62 }
63 }
64
65 throw length_error("No data.");
66 }
map_type::const_iterator const_iterator
Definition JGarage.hh:33

◆ getMax()

template<class T , const size_t factor = 0>
T JASTRONOMY::JGarage< T, factor >::getMax ( ) const
inline

Get maximal value.

Returns
value

Definition at line 74 of file JGarage.hh.

75 {
76 using namespace std;
77
78 for (const_reverse_iterator i = this->rbegin(); i != this->rend(); ++i) {
79 if (!i->empty()) {
80 return *max_element(i->begin(), i->end());
81 }
82 }
83
84 throw length_error("No data.");
85 }
map_type::const_reverse_iterator const_reverse_iterator
Definition JGarage.hh:34

◆ getKey()

template<class T , const size_t factor = 0>
static size_t JASTRONOMY::JGarage< T, factor >::getKey ( const T value)
inlinestatic

Get hash key corresponding to given value.

Parameters
valuevalue
Returns
key

Definition at line 94 of file JGarage.hh.

95 {
96 if (value > 0.0)
97 return value * factor;
98 else
99 return 0;
100 }

◆ put() [1/2]

template<class T , const size_t factor = 0>
void JASTRONOMY::JGarage< T, factor >::put ( const T value)
inline

Add value to container.

Parameters
valuevalue

Definition at line 108 of file JGarage.hh.

109 {
110 const size_t index = getKey(value);
111
112 if (index >= this->size()) {
113 this->resize(index + 1);
114 }
115
116 (*this)[index].push_back(value);
117 }
static size_t getKey(const T value)
Get hash key corresponding to given value.
Definition JGarage.hh:94

◆ put() [2/2]

template<class T , const size_t factor = 0>
template<class JFunction_t >
void JASTRONOMY::JGarage< T, factor >::put ( const size_t N,
const JFunction_t & object )
inline

Add values to container.

Parameters
Nnumber of values
objectfunction object returning value

Definition at line 127 of file JGarage.hh.

128 {
129 for (size_t i = 0; i != N; ++i) {
130 this->put(object());
131 }
132 }
void put(const T value)
Add value to container.
Definition JGarage.hh:108

◆ operator()()

template<class T , const size_t factor = 0>
template<class JFunction_t >
void JASTRONOMY::JGarage< T, factor >::operator() ( const JFunction_t & object) const
inline

For-each method.

Parameters
objectfunction object

Definition at line 141 of file JGarage.hh.

142 {
143 for (const_iterator i = this->begin(); i != this->end(); ++i) {
144 for (const T x : *i) {
145 object(x);
146 }
147 }
148 }

◆ getValue()

template<class T , const size_t factor = 0>
T JASTRONOMY::JGarage< T, factor >::getValue ( const double P) const
inline

Get minimal value corresponding given maximal probability.

Parameters
Pprobability [0,1>
Returns
value

Definition at line 157 of file JGarage.hh.

158 {
159 using namespace std;
160
161 if (P < 0.0 || P > 1.0) {
162 throw out_of_range("Invalid probability.");
163 }
164
165 const size_t N = this->getN();
166 const size_t M = N - (P * N);
167
168 if (N == 0) {
169 throw length_error("No data.");
170 }
171
172 if (M == 0) { return getMin(); }
173 if (M == N) { return getMax(); }
174
175 size_t n = N;
176
177 const_reverse_iterator q = this->rbegin();
178
179 while ((n -= q->size()) > M) {
180 ++q;
181 }
182
183 value_type buffer(q->begin(), q->end());
184
185 typename value_type::iterator p = next(buffer.begin(), M - n);
186
187 nth_element(buffer.begin(), p, buffer.end());
188
189 return *p;
190 }
T getMax() const
Get maximal value.
Definition JGarage.hh:74
size_t getN() const
Get total number of values.
Definition JGarage.hh:42
T getMin() const
Get minimal value.
Definition JGarage.hh:55

◆ getProbability()

template<class T , const size_t factor = 0>
double JASTRONOMY::JGarage< T, factor >::getProbability ( const T value) const
inline

Get maximal probability corresponding given minimal value.

Parameters
valuevalue
Returns
probability

Definition at line 199 of file JGarage.hh.

200 {
201 using namespace std;
202
203 const size_t N = this->getN();
204 const int M = getKey(value);
205
206 if (N == 0) {
207 throw length_error("No data.");
208 }
209
210 size_t n = 0;
211 int i = this->size() - 1;
212
213 for ( ; i != -1 && i > M; --i) {
214 n += (*this)[i].size();
215 }
216
217 if (i != -1) {
218 for (const T x : (*this)[i]) {
219 if (x >= value) {
220 n += 1;
221 }
222 }
223 }
224
225 return (double) n / (double) N;
226 }

The documentation for this struct was generated from the following file: