Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
dcdb
dcdb
Commits
46dc8a16
Commit
46dc8a16
authored
Aug 07, 2019
by
lu43jih
Browse files
Small change to quantile computation function
parent
a436328f
Changes
1
Hide whitespace changes
Inline
Side-by-side
analytics/includes/CommonStatistics.h
View file @
46dc8a16
...
...
@@ -93,36 +93,5 @@ void computeQuantiles(const std::vector<reading_t> &data, std::vector<reading_t>
}
}
void
computeQuantiles
(
const
std
::
vector
<
reading_t
>
&
data
,
std
::
vector
<
reading_t
>
&
quantiles
,
unsigned
int
NUMBER_QUANTILES
)
{
std
::
vector
<
reading_t
>
cdf
;
//!< cumulative distribution function (cfd)
cdf
.
assign
(
data
.
begin
(),
data
.
end
());
// we copy the vector to avoid changing the order to the original
std
::
sort
(
cdf
.
begin
(),
cdf
.
end
(),
[
](
const
reading_t
&
lhs
,
const
reading_t
&
rhs
)
{
return
lhs
.
value
<
rhs
.
value
;
});
if
(
cdf
.
empty
())
{
return
;
}
int
elementNumber
=
cdf
.
size
();
quantiles
.
resize
(
NUMBER_QUANTILES
+
1
);
//+min
float
factor
=
elementNumber
/
static_cast
<
float
>
(
NUMBER_QUANTILES
);
quantiles
[
0
].
value
=
cdf
[
0
].
value
;
quantiles
[
NUMBER_QUANTILES
].
value
=
cdf
[
cdf
.
size
()
-
1
].
value
;
for
(
unsigned
int
i
=
1
;
i
<
NUMBER_QUANTILES
;
i
++
)
{
if
(
elementNumber
>
1
)
{
int
idx
=
static_cast
<
int
>
(
std
::
floor
(
i
*
factor
));
float
rest
=
(
i
*
factor
)
-
idx
;
if
(
idx
==
0
){
quantiles
[
i
].
value
=
cdf
[
0
].
value
;
quantiles
[
i
].
timestamp
=
cdf
[
0
].
timestamp
;
}
else
{
quantiles
[
i
].
value
=
cdf
[
idx
-
1
].
value
+
rest
*
(
cdf
[
idx
].
value
-
cdf
[
idx
-
1
].
value
);
quantiles
[
i
].
timestamp
=
cdf
[
idx
].
timestamp
;
}
}
else
{
//optimization, we don't need to calculate all the quantiles
quantiles
[
i
].
value
=
cdf
[
0
].
value
;
quantiles
[
i
].
value
=
cdf
[
0
].
timestamp
;
}
}
}
#endif
/* ANALYTICS_INCLUDES_COMMONSTATISTICS_H_ */
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment