|
7 | 7 | sys.path.append(join(dirname(__file__), "..")) |
8 | 8 |
|
9 | 9 | from progpy import PrognosticsModel, LinearModel |
10 | | -from progpy.models import ThrownObject, BatteryElectroChem, PneumaticValveBase |
| 10 | +from progpy.models import ThrownObject, BatteryElectroChem, PneumaticValveBase, BatteryElectroChemEOD |
11 | 11 | from progpy.state_estimators import ParticleFilter, KalmanFilter, UnscentedKalmanFilter |
12 | 12 | from progpy.uncertain_data import ScalarData, MultivariateNormalDist, UnweightedSamples |
13 | 13 |
|
@@ -561,6 +561,20 @@ def future_loading(t, x=None): |
561 | 561 | for t, u, z in zip(times, inputs.data, outputs.data): |
562 | 562 | kf.estimate(t, u, z) |
563 | 563 |
|
| 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 | + |
564 | 578 | # This allows the module to be executed directly |
565 | 579 | def main(): |
566 | 580 | # This ensures that the directory containing StateEstimatorTemplate is in the python search directory |
|
0 commit comments