Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
1f74df12
Commit
1f74df12
authored
6 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Add average trajectories with dtw
parent
94b40f80
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
navipy/trajectories/tools.py
+46
-0
46 additions, 0 deletions
navipy/trajectories/tools.py
setup.py
+4
-2
4 additions, 2 deletions
setup.py
with
50 additions
and
2 deletions
navipy/trajectories/tools.py
+
46
−
0
View file @
1f74df12
...
...
@@ -6,6 +6,52 @@ from scipy.interpolate import interp1d
import
pandas
as
pd
import
numpy
as
np
import
navipy.tools
as
tratools
import
fastdtw
from
navipy.trajectories
import
Trajectory
def
averaged_trajectory
(
alltraj
):
"""
Calculate an average trajectory
Trajectories are aligned by using dynamic time wraping (dtw).
\
The alignment is relative to the first trajectory in the list. Therefore
\
the average trajectory will have the same length that the first trajectory.
Aligned trajectory are aligned as follow. The mean of average position
\
corresponding to the time of the first trajectory devided by the number of
\
trajectory are summed over all trajectory. For the orientation, the circular
\
mean is used according to `Statistics on Sphere` Geoffrey S. Watson 1983.
:param alltraj: A list of trajectories
:returns: An average trajectory
"""
rotconv
=
alltraj
[
0
].
rotation_mode
traj_1
=
alltraj
[
0
].
dropna
().
values
avg_traj
=
traj_1
.
copy
()
avg_traj
[:,
0
:
3
]
/=
len
(
alltraj
)
for
traj_2
in
alltraj
[
1
:]:
traj_2
=
traj_2
.
dropna
().
values
x
=
np
.
array
(
traj_1
[:,
[
0
,
1
,
2
]],
dtype
=
'
float
'
)
y
=
np
.
array
(
traj_2
[:,
[
0
,
1
,
2
]],
dtype
=
'
float
'
)
test
=
fastdtw
.
fastdtw
(
x
,
y
)
# average
for
ii
,
group
in
pd
.
DataFrame
(
test
[
1
]).
groupby
(
0
):
# average position
avg_traj
[
ii
,
0
:
3
]
+=
np
.
mean
(
traj_2
[
group
.
loc
[:,
1
],
0
:
3
],
axis
=
0
)
/
len
(
alltraj
)
# average angles
# see Statistics On Spheres", Geoffrey S. Watson,
# University of Arkansas Lecture Notes
# in the Mathematical Sciences, 1983 John Wiley & Son
for
kk
in
range
(
3
,
6
):
sinsum
=
np
.
sum
(
np
.
sin
(
traj_2
[
group
.
loc
[:,
1
],
kk
]),
axis
=
0
)
cossum
=
np
.
sum
(
np
.
cos
(
traj_2
[
group
.
loc
[:,
1
],
kk
]),
axis
=
0
)
sinsum
+=
np
.
sin
(
avg_traj
[
ii
,
kk
])
cossum
+=
np
.
cos
(
avg_traj
[
ii
,
kk
])
avg_traj
[
ii
,
kk
]
=
np
.
arctan2
(
sinsum
,
cossum
)
return
Trajectory
().
from_array
(
avg_traj
,
rotconv
=
rotconv
)
def
interpolate_markers
(
markers
,
kind
=
'
cubic
'
):
...
...
This diff is collapsed.
Click to expand it.
setup.py
+
4
−
2
View file @
1f74df12
...
...
@@ -50,7 +50,8 @@ setup_dict = {'name': 'navipy',
'
ipython
'
,
'
yaml
'
,
'
PIL
'
,
'
cv2
'
],
'
cv2
'
,
'
fastdtw
'
],
'
install_requires
'
:
[
"
numpy
"
,
'
pandas
'
,
'
matplotlib
'
,
...
...
@@ -66,7 +67,8 @@ setup_dict = {'name': 'navipy',
'
tables
'
,
'
nbsphinx
'
,
'
opencv-python
'
,
'
coverage
'
],
'
coverage
'
,
'
fastdtw
'
],
'
package_data
'
:
{
'
navipy
'
:
package_data_files
(
"
navipy
"
)},
'
include_package_data
'
:
True
,
...
...
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