dstl / Stone-Soup

A software project to provide the target tracking community with a framework for the development and testing of tracking algorithms.
https://stonesoup.rtfd.io
MIT License
385 stars 127 forks source link

Could not import "Particles" #797

Closed hama6767 closed 1 year ago

hama6767 commented 1 year ago

When I tried the tutorial of the particle filter, I get an error.

https://stonesoup.readthedocs.io/en/v0.1b9/auto_tutorials/04_ParticleFilter.html#sphx-glr-auto-tutorials-04-particlefilter-py

It seems to be failed importing "Particles" library.

In

from scipy.stats import multivariate_normal

from stonesoup.types.particle import Particles
from stonesoup.types.numeric import Probability  # Similar to a float type
from stonesoup.types.state import ParticleState
from stonesoup.types.array import StateVectors

number_particles = 1000

# Sample from the prior Gaussian distribution
samples = multivariate_normal.rvs(np.array([0, 1, 0, 1]),
                                  np.diag([1.5, 0.5, 1.5, 0.5]),
                                  size=number_particles)

# Create state vectors and weights for particles
particles = Particles(state_vector=StateVectors(samples.T),
                      weight=np.array([Probability(1/number_particles)]*number_particles)
                      )

# Create prior particle state.
prior = ParticleState(particles, timestamp=start_time)

Out

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-11-a85cce145242>](https://localhost:8080/#) in <cell line: 3>()
      1 from scipy.stats import multivariate_normal
      2 
----> 3 from stonesoup.types.particle import Particles
      4 from stonesoup.types.numeric import Probability  # Similar to a float type
      5 from stonesoup.types.state import ParticleState

ImportError: cannot import name 'Particles' from 'stonesoup.types.particle' (/usr/local/lib/python3.10/dist-packages/stonesoup/types/particle.py)

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

The function itself looks existing https://stonesoup.readthedocs.io/en/v0.1b9/stonesoup.types.html#stonesoup.types.particle.Particles

but the code is none? https://github.com/dstl/Stone-Soup/blob/main/stonesoup/types/particle.py

sglvladi commented 1 year ago

Hi @hama6767,

You seem to be following the tutorial for version v0.1b9. The Particles class was dropped in v0.1b10, so I suspect you have version >=0.1b10 installed. I suggest you try running the tutorial for the latest release:

https://stonesoup.readthedocs.io/en/v0.1b12/auto_tutorials/04_ParticleFilter.html

hama6767 commented 1 year ago

Hello,

Thank you. I perfectly work this demo with latest version. Thank you for convinience.