Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Simox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Leander Singer
Simox
Commits
b781e152
Commit
b781e152
authored
6 years ago
by
Rainer Kartmann
Browse files
Options
Downloads
Patches
Plain Diff
Added statistics measures
parent
c21b2469
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
VirtualRobot/CMakeLists.txt
+2
-0
2 additions, 0 deletions
VirtualRobot/CMakeLists.txt
VirtualRobot/math/statistics/measures.cpp
+110
-0
110 additions, 0 deletions
VirtualRobot/math/statistics/measures.cpp
VirtualRobot/math/statistics/measures.h
+31
-0
31 additions, 0 deletions
VirtualRobot/math/statistics/measures.h
with
143 additions
and
0 deletions
VirtualRobot/CMakeLists.txt
+
2
−
0
View file @
b781e152
...
...
@@ -334,6 +334,7 @@ math/Plane.cpp
math/Primitive.cpp
math/Triangle.cpp
math/WeightedAverage.cpp
math/statistics/measures.cpp
Util/xml/tinyxml2.cpp
Util/json/eigen_conversion.cpp
)
...
...
@@ -507,6 +508,7 @@ math/TransformedFunctionR1R3.h
math/TransformedFunctionR2R3.h
math/Triangle.h
math/WeightedAverage.h
math/statistics/measures.h
Util/xml/tinyxml2.h
Util/json/json.hpp
Util/json/eigen_conversion.h
...
...
This diff is collapsed.
Click to expand it.
VirtualRobot/math/statistics/measures.cpp
0 → 100644
+
110
−
0
View file @
b781e152
#include
"measures.h"
#include
<algorithm>
#include
<cmath>
#include
<stdexcept>
namespace
math
{
namespace
stat
{
void
sort
(
std
::
vector
<
float
>&
values
)
{
std
::
sort
(
values
.
begin
(),
values
.
end
());
}
std
::
vector
<
float
>
sorted
(
const
std
::
vector
<
float
>&
values
)
{
std
::
vector
<
float
>
s
=
values
;
std
::
sort
(
s
.
begin
(),
s
.
end
());
return
s
;
}
float
min
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
)
{
return
isSorted
?
values
.
front
()
:
*
std
::
min_element
(
values
.
begin
(),
values
.
end
());
}
float
max
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
)
{
return
isSorted
?
values
.
back
()
:
*
std
::
max_element
(
values
.
begin
(),
values
.
end
());
}
float
mean
(
const
std
::
vector
<
float
>&
values
)
{
if
(
values
.
empty
()
==
0
)
throw
std
::
range_error
(
"Given values are empty."
);
float
sum
=
0
;
for
(
float
v
:
values
)
{
sum
+=
v
;
}
return
sum
/
values
.
size
();
}
float
stddev
(
const
std
::
vector
<
float
>&
values
)
{
return
stddev
(
values
,
mean
(
values
));
}
float
stddev
(
const
std
::
vector
<
float
>&
values
,
float
mean
)
{
float
sum
=
0
;
for
(
float
v
:
values
)
{
float
diff
=
v
-
mean
;
sum
+=
diff
*
diff
;
}
float
variance
=
sum
/
(
values
.
size
()
-
1
);
return
std
::
sqrt
(
variance
);
}
float
quantile
(
const
std
::
vector
<
float
>&
_values
,
float
p
,
bool
isSorted
)
{
const
std
::
vector
<
float
>&
values
=
isSorted
?
_values
:
sorted
(
_values
);
float
location
=
p
*
values
.
size
();
std
::
size_t
floor
=
static_cast
<
std
::
size_t
>
(
std
::
floor
(
location
));
std
::
size_t
ceil
=
static_cast
<
std
::
size_t
>
(
std
::
ceil
(
location
));
if
(
floor
==
ceil
)
{
return
values
.
at
(
floor
);
}
else
{
float
t
=
location
-
floor
;
return
(
1
-
t
)
*
values
.
at
(
floor
)
+
t
*
values
.
at
(
ceil
);
}
}
float
lowerQuartile
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
)
{
return
quantile
(
values
,
.25
,
isSorted
);
}
float
median
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
)
{
return
quantile
(
values
,
.5
,
isSorted
);
}
float
upperQuartile
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
)
{
return
quantile
(
values
,
.75
,
isSorted
);
}
float
interquartileRange
(
const
std
::
vector
<
float
>&
_values
,
bool
isSorted
)
{
const
std
::
vector
<
float
>&
values
=
isSorted
?
_values
:
sorted
(
_values
);
return
interquartileRange
(
lowerQuartile
(
values
,
true
),
upperQuartile
(
values
,
true
));
}
float
interquartileRange
(
float
lowerQuartile
,
float
upperQuartile
)
{
return
upperQuartile
-
lowerQuartile
;
}
}}
This diff is collapsed.
Click to expand it.
VirtualRobot/math/statistics/measures.h
0 → 100644
+
31
−
0
View file @
b781e152
#pragma once
#include
<vector>
namespace
math
{
namespace
stat
{
void
sort
(
std
::
vector
<
float
>&
values
);
std
::
vector
<
float
>
sorted
(
const
std
::
vector
<
float
>&
values
);
float
min
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
max
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
mean
(
const
std
::
vector
<
float
>&
values
);
float
stddev
(
const
std
::
vector
<
float
>&
values
);
float
stddev
(
const
std
::
vector
<
float
>&
values
,
float
mean
);
float
quantile
(
const
std
::
vector
<
float
>&
values
,
float
p
,
bool
isSorted
=
false
);
float
lowerQuartile
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
median
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
upperQuartile
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
interquartileRange
(
const
std
::
vector
<
float
>&
values
,
bool
isSorted
=
false
);
float
interquartileRange
(
float
lowerQuartile
,
float
upperQuartile
);
}}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment