Skip to content

Commit 9ba241a

Browse files
committed
Add new test
1 parent 6ace408 commit 9ba241a

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tests/test_state_estimators.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sys.path.append(join(dirname(__file__), ".."))
88

99
from progpy import PrognosticsModel, LinearModel
10-
from progpy.models import ThrownObject, BatteryElectroChem, PneumaticValveBase
10+
from progpy.models import ThrownObject, BatteryElectroChem, PneumaticValveBase, BatteryElectroChemEOD
1111
from progpy.state_estimators import ParticleFilter, KalmanFilter, UnscentedKalmanFilter
1212
from progpy.uncertain_data import ScalarData, MultivariateNormalDist, UnweightedSamples
1313

@@ -561,6 +561,20 @@ def future_loading(t, x=None):
561561
for t, u, z in zip(times, inputs.data, outputs.data):
562562
kf.estimate(t, u, z)
563563

564+
def test_PF_particle_ordering(self):
565+
"""
566+
This is testing for a bug found by @mstraut where particle filter was mixing up the keys if users:
567+
1. Do not call m.initialize(), and instead
568+
2. provide a state as a dictionary instead of a state container, and
569+
3. order the states in a different order than m.states
570+
"""
571+
m = BatteryElectroChemEOD()
572+
x0 = m.parameters['x0'] # state as a dictionary with the wrong order
573+
filt = ParticleFilter(m, x0, num_particles=2)
574+
for key in m.states:
575+
self.assertEqual(filt.particles[key][0], x0[key])
576+
self.assertEqual(filt.particles[key][1], x0[key])
577+
564578
# This allows the module to be executed directly
565579
def main():
566580
# This ensures that the directory containing StateEstimatorTemplate is in the python search directory

0 commit comments

Comments
 (0)