Были похожие вопросы, но ни у одного из них не было ответа, который я искал. Я получаю: AttributeError: 'ParticleFilter' object has no attribute 'initialCoordinates'
(функция create_gaussian_particles ), хотя я определил в конструкторе init и создал его экземпляр, я не могу точно понять, в чем проблема, Я пытался найти себя, но ничего, вот код:
import numpy as np
class ParticleFilter(object):
def __init__(self, N, initialConditions, imageSize):
self.create_particles(N, initialConditions, imageSize)
self.create_weights(N)
self.imageSize = imageSize
self.initialCoordinates = np.array([initialConditions[0, 0], initialConditions[0, 1]])
self.initialStdDev = np.array([initialConditions[1, 0], initialConditions[1, 1]])
def create_particles(self, N, initialConditions, imageSize):
if initialConditions is None:
self.create_uniform_particles(N, imageSize)
else:
self.create_gaussian_particles(N, initialConditions)
def create_gaussian_particles(self, N, initialConditions):
self.particles = np.empty((N, 2))
self.particles[:, 0] = self.initialCoordinates[0] + (np.random.randn(N) * self.initialStdDev[0])
self.particles[:, 1] = self.initialCoordinates[1] + (np.random.randn(N) * self.initialStdDev[1])
def create_uniform_particles(self, N, imageSize):
pass
def create_weights(self, N):
pass
N = 1000
initialPosition = np.array([10, 10])
initialStdDev = np.array([5, 5])
initialConditions = np.array([initialPosition, initialStdDev])
imageSize = np.array([480, 360])
pf = ParticleFilter(N, initialConditions, imageSize)
File "c:/Projects/pf2.py", line 65, in <module>
pf = ParticleFilter(N, initialConditions, imageSize)
File "c://Projects/pf2.py", line 8, in __init__
self.create_particles(N, initialConditions, imageSize)
File "c://Projects/pf2.py", line 18, in create_particles
self.create_gaussian_particles(N, initialConditions)
File "c://Projects/pf2.py", line 22, in create_gaussian_particles
self.particles[:, 0] = self.initialCoordinates[0] + (np.random.randn(N) * self.initialStdDev[0])
AttributeError: 'ParticleFilter' object has no attribute 'initialCoordinates'