Example #1
0
 def atest_probabilistic_resampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [1,3,0,0,0,0]
     solutions = self.resample(indices)
     dautils.probabilisticResampling(self.resamplingDrifterSet, self.resamplingVar)
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "probabilistic resampling, probabilistic duplicates")
Example #2
0
    def hhhtest_default_constructor(self):
        self.create_resampling_particle_set()
        defaultParticleSet = self.resamplingParticleSet

        self.assertEqual(defaultParticleSet.getNumParticles(),
                         self.resampleNumParticles)
        self.assertEqual(defaultParticleSet.getObservationVariance(), 0.1)

        positions = defaultParticleSet.observeParticles()
        defaultPosition = [0.0, 0.0]
        self.assertEqual(positions.shape, ((self.resampleNumParticles, 2)))
        for i in range(self.resampleNumParticles):
            self.assertEqual(positions[i, :].tolist(), defaultPosition)

        observation = defaultParticleSet.observeTrueState()
        self.assertEqual(observation.shape, ((2, )))
        self.assertEqual(observation.tolist(), defaultPosition)

        self.assertEqual(defaultParticleSet.getDomainSizeX(), 1.0)
        self.assertEqual(defaultParticleSet.getDomainSizeY(), 1.0)

        weight = 1.0 / self.resampleNumParticles
        weights = [weight] * self.resampleNumParticles
        self.assertEqual(
            dautils.getGaussianWeight(
                defaultParticleSet.getDistances(),
                defaultParticleSet.getObservationVariance()).tolist(), weights)
        self.assertEqual(
            dautils.getCauchyWeight(
                defaultParticleSet.getDistances(),
                defaultParticleSet.getObservationVariance()).tolist(), weights)

        # Check boundary condition
        self.assertEqual(defaultParticleSet.getBoundaryConditions().get(),
                         [1, 1, 1, 1])
Example #3
0
 def atest_probabilistic_resampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [1,3,0,0,0,0]
     solutions = self.resample(indices)
     dautils.probabilisticResampling(self.resamplingDrifterSet, self.resamplingVar)
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "probabilistic resampling, probabilistic duplicates")
 def test_residual_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,3,3,1,4]
     solutions = self.resample(indices)
     dautils.residualSampling(self.resamplingParticleSet, self.resamplingVar)
     assert2DListAlmostEqual(self, self.resamplingParticleSet.observeParticles().tolist(), solutions, 2, "residual sampling, probabilistic duplicates")
Example #5
0
 def atest_stochastic_universal_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,1,3,3,4]
     solutions = self.resample(indices)
     dautils.stochasticUniversalSampling(self.resamplingDrifterSet, self.resamplingVar)
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "stochastic universal sampling, probabilistic duplicates")
Example #6
0
 def atest_stochastic_universal_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,1,3,3,4]
     solutions = self.resample(indices)
     dautils.stochasticUniversalSampling(self.resamplingDrifterSet, self.resamplingVar)
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "stochastic universal sampling, probabilistic duplicates")
Example #7
0
 def atest_monte_carlo_metropolis_hasting_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,0,3,4,4]
     solutions = self.resample(indices)
     dautils.metropolisHastingSampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions)
Example #8
0
 def atest_monte_carlo_metropolis_hasting_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,0,3,4,4]
     solutions = self.resample(indices)
     dautils.metropolisHastingSampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions)
Example #9
0
 def atest_stochastic_universal_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,1,3,3,4]
     solutions = self.resample(indices)
     dautils.stochasticUniversalSampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), \
                      solutions)
Example #10
0
 def atest_probabilistic_resampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [1,3,0,0,0,0]
     solutions = self.resample(indices)
     dautils.probabilisticResampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), \
                      solutions)
Example #11
0
 def test_residual_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0, 0, 3, 3, 1, 4]
     solutions = self.resample(indices)
     dautils.residualSampling(self.resamplingParticleSet)
     self.assertEqual(self.resamplingParticleSet.observeParticles().tolist(), \
                      solutions)
 def test_residual_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,3,3,1,4]
     solutions = self.resample(indices)
     dautils.residualSampling(self.resamplingParticleSet)
     self.assertEqual(self.resamplingParticleSet.observeParticles().tolist(), \
                      solutions)
Example #13
0
 def atest_monte_carlo_metropolis_hasting_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,0,3,4,4]
     solutions = self.resample(indices)
     dautils.metropolisHastingSampling(self.resamplingDrifterSet, self.resamplingVar)
     #print self.resamplingDrifterSet.getDrifterPositions().tolist()
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "metropolis hasting sampling, probabilistic duplicates")
Example #14
0
 def atest_stochastic_universal_sampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0, 0, 1, 3, 3, 4]
     solutions = self.resample(indices)
     dautils.stochasticUniversalSampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), \
                      solutions)
Example #15
0
 def atest_probabilistic_resampling_with_duplicates(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [1, 3, 0, 0, 0, 0]
     solutions = self.resample(indices)
     dautils.probabilisticResampling(self.resamplingDrifterSet)
     self.assertEqual(self.resamplingDrifterSet.getDrifterPositions().tolist(), \
                      solutions)
Example #16
0
 def atest_monte_carlo_metropolis_hasting_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0,0,0,3,4,4]
     solutions = self.resample(indices)
     dautils.metropolisHastingSampling(self.resamplingDrifterSet, self.resamplingVar)
     #print self.resamplingDrifterSet.getDrifterPositions().tolist()
     assert2DListAlmostEqual(self, self.resamplingDrifterSet.getDrifterPositions().tolist(), solutions, 2, "metropolis hasting sampling, probabilistic duplicates")
Example #17
0
 def test_residual_sampling(self):
     self.set_positions_resampling_set()
     setNpRandomSeed()
     indices = [0, 0, 3, 3, 1, 4]
     solutions = self.resample(indices)
     dautils.residualSampling(self.resamplingParticleSet,
                              self.resamplingVar)
     assert2DListAlmostEqual(
         self,
         self.resamplingParticleSet.observeParticles().tolist(), solutions,
         2, "residual sampling, probabilistic duplicates")
Example #18
0
 def test_gaussian_weights(self):
     self.set_positions_resampling_set()
     obtainedWeights = dautils.getGaussianWeight(
         self.resamplingParticleSet.getDistances(),
         self.resamplingParticleSet.getObservationVariance())
     referenceWeights = [
         3.77361928e-01, 1.22511481e-01, 1.26590824e-04, 3.77361928e-01,
         1.22511481e-01, 1.26590824e-04
     ]
     assertListAlmostEqual(self, obtainedWeights.tolist(), referenceWeights,
                           6, 'gaussian weights')
Example #19
0
 def test_cauchy_weights(self):
     self.set_positions_resampling_set()
     obtainedWeights = dautils.getCauchyWeight(
         self.resamplingParticleSet.getDistances(),
         self.resamplingParticleSet.getObservationVariance())
     referenceWeights = [
         0.28413284, 0.16789668, 0.04797048, 0.28413284, 0.16789668,
         0.04797048
     ]
     assertListAlmostEqual(self, obtainedWeights.tolist(), referenceWeights,
                           6, 'cauchy weights')