Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Multiple Target Tracking
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
phd-courses
Multiple Target Tracking
Commits
3e71b84d
Commit
3e71b84d
authored
3 years ago
by
Anton Kullberg
Browse files
Options
Downloads
Patches
Plain Diff
py: updated data generation for ex2
parent
69f069ac
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sim.py
+21
-15
21 additions, 15 deletions
src/sim.py
with
21 additions
and
15 deletions
src/sim.py
+
21
−
15
View file @
3e71b84d
import
numpy
as
np
def
generate_data
(
trajector
y
,
sensor_model
,
clutter_model
,
rng
=
None
):
def
generate_data
(
trajector
ies
,
sensor_model
,
clutter_model
,
rng
=
None
):
"""
Simulates measurements along a state trajectory according to a sensor and clutter model.
The function assumes Gaussian white noise affecting the measurements.
Parameters
----------
trajector
y :
numpy.ndarray
A nx by N array where nx is the state dimension and N is the number of time steps
trajector
ies : dict of
numpy.ndarray
s
A
dict with entries with
nx by N array
s
where nx is the state dimension and N is the number of time steps
. Sample time T=1 is assumed.
sensor_model : dict
A dictionary with the following entries:
h : callable
...
...
@@ -26,23 +26,28 @@ def generate_data(trajectory, sensor_model, clutter_model, rng=None):
rng : Generator
A numpy random number generator. Can be constructed by e.g. np.random.default_rng()
Returns
-------
list of numpy.ndarray
Each list item is a numpy.ndarray with zero or more measurements (ny by x)
"""
N
=
max
([
T
.
shape
[
1
]
for
key
,
T
in
trajectories
.
items
()])
# Maximum length of a trajectory interesting for this purpose
if
rng
is
None
:
rng
=
np
.
random
.
default_rng
()
measurements
=
[]
ny
=
sensor_model
[
'
h
'
](
trajectory
[:,
0
]).
size
for
state
in
trajectory
.
T
:
#.T to aid for-loop
ny
=
sensor_model
[
'
h
'
](
trajectories
[
next
(
iter
(
trajectories
))][:,
0
]).
size
# Get the dimensionality of the measurements
for
n
in
range
(
N
):
# Determine amount of clutter this time
nclutter
=
rng
.
poisson
(
lam
=
clutter_model
[
'
lam
'
])
trajs
=
[
T
for
key
,
T
in
trajectories
.
items
()
if
n
<
T
.
shape
[
1
]]
# Figure out what trajectories are active right now
Ntrajs
=
len
(
trajs
)
# Calc. number of trajectories present in the current time step
# Initialize an array w/ the number of measurements this time step
cur_measurements
=
np
.
empty
((
ny
,
nclutter
+
1
))
cur_measurements
=
np
.
empty
((
ny
,
nclutter
+
Ntrajs
))
cur_measurements
[:,
:]
=
np
.
NaN
if
nclutter
!=
0
:
# Calc. clutter states
...
...
@@ -53,15 +58,16 @@ def generate_data(trajectory, sensor_model, clutter_model, rng=None):
high
=
clutter_model
[
'
volume
'
][
'
ymax
'
],
size
=
(
nclutter
,))
]).
reshape
(
-
1
,
nclutter
)
cur_measurements
[:,
:
-
1
]
=
(
sensor_model
[
'
h
'
](
clutter_states
)
+
\
cur_measurements
[:,
:
nclutter
]
=
(
sensor_model
[
'
h
'
](
clutter_states
)
+
\
rng
.
multivariate_normal
(
mean
=
np
.
zeros
((
ny
,)),
cov
=
sensor_model
[
'
R
'
],
size
=
(
nclutter
)).
squeeze
().
T
).
reshape
(
-
1
,
nclutter
)
# Generate measurement of target (possibly)
if
rng
.
uniform
()
<=
sensor_model
[
'
PD
'
]:
y
=
sensor_model
[
'
h
'
](
state
)
+
\
rng
.
multivariate_normal
(
mean
=
np
.
zeros
((
ny
,)),
cov
=
sensor_model
[
'
R
'
])
cur_measurements
[:,
-
1
]
=
y
.
flatten
()
# Add actual observation to array
else
:
cur_measurements
=
cur_measurements
[:,
:
-
1
]
# Generate measurement of target(s) (possibly)
for
nt
,
traj
in
enumerate
(
trajs
):
if
rng
.
uniform
()
<=
sensor_model
[
'
PD
'
]:
y
=
sensor_model
[
'
h
'
](
traj
[:,
n
])
+
\
rng
.
multivariate_normal
(
mean
=
np
.
zeros
((
ny
,)),
cov
=
sensor_model
[
'
R
'
])
cur_measurements
[:,
nclutter
+
nt
]
=
y
.
flatten
()
# Add actual observation to array
cur_measurements
=
cur_measurements
[
~
np
.
isnan
(
cur_measurements
)].
reshape
(
ny
,
-
1
)
# Remove nan measurements (i.e. targets that did not generate a measurement)
measurements
.
append
(
cur_measurements
)
return
measurements
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