Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
particle-filter-for-python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Rob Moss
particle-filter-for-python
Commits
cb269565
Commit
cb269565
authored
4 years ago
by
Rob Moss
Browse files
Options
Downloads
Patches
Plain Diff
Add a simple post-regularisation test case
parent
1ee9a139
No related branches found
No related tags found
No related merge requests found
Pipeline
#7119
passed
4 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_resample.py
+81
-1
81 additions, 1 deletion
tests/test_resample.py
with
81 additions
and
1 deletion
tests/test_resample.py
+
81
−
1
View file @
cb269565
...
...
@@ -3,7 +3,7 @@
import
numpy
as
np
import
pytest
from
pypfilt.resample
import
resample
,
resample_ixs
from
pypfilt.resample
import
post_regularise
,
resample
,
resample_ixs
from
pypfilt.context
import
Scaffold
...
...
@@ -58,3 +58,83 @@ def test_resample_ixs(method):
else
:
pytest
.
fail
(
"
Failure after {} loops with {} resampling
"
.
format
(
n_tries
,
method
))
def
dummy_model
(
fields
,
smooth_fields
):
"""
Construct a dummy model that only defines its field names, field types,
and which fields can be smoothed.
:param fields: The list of field names, all of which are treated as
floating-point values.
:param smooth_fields: The list of field names that can be smoothed.
"""
class
DummyModel
:
def
field_names
(
self
):
return
fields
def
field_types
(
self
,
ctx
):
return
[(
f
,
float
)
for
f
in
fields
]
def
can_smooth
(
self
):
return
smooth_fields
return
DummyModel
()
def
test_post_regularise
():
"""
Test post-regularisation using an ensemble of 10 particles for a model of
three variables.
"""
model
=
dummy_model
([
'
a
'
,
'
b
'
,
'
c
'
],
[
'
a
'
,
'
b
'
,
'
c
'
])
comps
=
{
'
random
'
:
{
'
resample
'
:
np
.
random
.
default_rng
(
seed
=
202101
),
},
'
model
'
:
model
,
}
params
=
{
'
resample
'
:
{
'
reg_toln
'
:
1e-8
,
'
regularise_or_fail
'
:
False
,
},
'
model
'
:
{
'
param_bounds
'
:
{
'
a
'
:
(
-
100
,
100
),
'
b
'
:
(
-
100
,
100
),
},
},
'
hist
'
:
{
'
lookup_cols
'
:
{},
}
}
ctx
=
Scaffold
(
component
=
comps
,
params
=
params
)
# NOTE: at a minimum, we need 'weight', 'prev_ix', 'state_vec'.
px
=
np
.
array
([
(
0.1
,
0
,
(
1.0
,
1.0
,
1.0
)),
(
0.1
,
0
,
(
1.0
,
2.0
,
1.0
)),
(
0.1
,
0
,
(
1.0
,
3.0
,
1.0
)),
(
0.1
,
0
,
(
1.0
,
4.0
,
1.0
)),
(
0.1
,
0
,
(
1.0
,
5.0
,
1.0
)),
(
0.1
,
1
,
(
2.0
,
6.0
,
1.0
)),
(
0.1
,
1
,
(
2.0
,
7.0
,
1.0
)),
(
0.1
,
1
,
(
2.0
,
8.0
,
1.0
)),
(
0.1
,
1
,
(
2.0
,
9.0
,
1.0
)),
(
0.1
,
1
,
(
2.0
,
10.0
,
1.0
)),
],
dtype
=
[(
'
weight
'
,
np
.
float_
),
(
'
prev_ix
'
,
np
.
int_
),
(
'
state_vec
'
,
model
.
field_types
(
ctx
))])
new_px
=
np
.
copy
(
px
)
post_regularise
(
ctx
,
px
,
new_px
)
assert
(
np
.
array_equal
(
px
[
'
weight
'
],
new_px
[
'
weight
'
]))
assert
(
np
.
array_equal
(
px
[
'
prev_ix
'
],
new_px
[
'
prev_ix
'
]))
assert
(
not
np
.
array_equal
(
px
[
'
state_vec
'
],
new_px
[
'
state_vec
'
]))
assert
(
np
.
array_equal
(
px
[
'
state_vec
'
][
'
c
'
],
new_px
[
'
state_vec
'
][
'
c
'
]))
abs_diff_a
=
np
.
abs
(
new_px
[
'
state_vec
'
][
'
a
'
]
-
px
[
'
state_vec
'
][
'
a
'
])
assert
(
np
.
mean
(
abs_diff_a
)
<
0.2
)
assert
(
np
.
mean
(
abs_diff_a
)
>
0.01
)
abs_diff_b
=
np
.
abs
(
new_px
[
'
state_vec
'
][
'
b
'
]
-
px
[
'
state_vec
'
][
'
b
'
])
assert
(
np
.
mean
(
abs_diff_b
)
<
1.0
)
assert
(
np
.
mean
(
abs_diff_b
)
>
0.2
)
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