46 float pruningThreshold,
47 const GaussianMixtureAssociationMethodBasePtr& assMethod) :
49 agingFactor(agingFactor),
50 pruningThreshold(pruningThreshold),
51 associationMethod(assMethod)
68 const ::Ice::Current& = Ice::emptyCurrent)
override
74 return EntityBasePtr();
77 MultivariateNormalDistributionBasePtr posGaussian = instance->getPositionUncertainty();
82 ObjectInstancePtr::dynamicCast(instance->ice_clone());
85 fusedInstance->setId(
"");
91 fusedInstance->getPositionAttribute()->setValueWithUncertainty(
92 instance->getPositionAttribute()->getValue(), posGM);
110 const EntityBasePtr& newEntity,
111 const ::Ice::Current& = Ice::emptyCurrent)
override
114 ObjectInstancePtr::dynamicCast(oldEntity->ice_clone());
115 EntityAttributeBasePtr posAttr = fusedInstance->getPositionAttribute();
117 GaussianMixtureDistributionPtr::dynamicCast(posAttr->getUncertainty());
124 posGM->scaleComponents(agingFactor);
126 MultivariateNormalDistributionBasePtr newUncertainty =
127 newInstance->getPositionUncertainty();
128 GaussianMixtureComponent newComp;
129 newComp.gaussian = newUncertainty;
133 GaussianMixtureDistributionPtr::dynamicCast(posGM->clone());
135 int associatedCompIndex =
136 associationMethod->getAssociatedComponentIndex(normGM, newComp);
138 if (associatedCompIndex >= 0)
140 GaussianMixtureComponent associatedComp =
141 posGM->getComponent(associatedCompIndex);
142 GaussianMixtureComponent associatedNormComp =
143 normGM->getComponent(associatedCompIndex);
144 GaussianMixtureComponent newNormComp = normGM->getComponent(posGM->size() - 1);
145 GaussianMixtureComponent fusedComp =
146 fuseGaussianComponents(associatedNormComp, newNormComp);
147 fusedComp.weight = newComp.weight + associatedComp.weight;
148 posGM->setComponent(associatedCompIndex, fusedComp);
152 posGM->addComponent(newComp);
156 if (pruningThreshold > 0)
158 posGM->pruneComponents(pruningThreshold);
165 GaussianMixtureComponent modalComp = posGM->getModalComponent();
167 if (modalComp.gaussian)
170 NormalDistributionPtr::dynamicCast(modalComp.gaussian);
173 fusedInstance->getPosition()->getFrame(),
174 fusedInstance->getPosition()->agent);
175 fusedInstance->setPosition(posMean);
176 fusedInstance->getPositionAttribute()->setValueWithUncertainty(
177 fusedInstance->getPositionAttribute()->getValue(), posGM);
178 return fusedInstance;
182 return EntityBasePtr();
187 return EntityBasePtr();
193 float pruningThreshold;
194 GaussianMixtureAssociationMethodBasePtr associationMethod;
196 GaussianMixtureComponent
197 fuseGaussianComponents(
const GaussianMixtureComponent& oldComp,
198 const GaussianMixtureComponent& newComp)
201 NormalDistributionPtr::dynamicCast(oldComp.gaussian);
203 NormalDistributionPtr::dynamicCast(newComp.gaussian);
205 const Eigen::VectorXf x1 = oldGaussian->toEigenMean();
206 const Eigen::VectorXf x2 = newGaussian->toEigenMean();
207 const Eigen::MatrixXf p1 = oldGaussian->toEigenCovariance();
208 const Eigen::MatrixXf p2 = newGaussian->toEigenCovariance();
210 const float w1 = oldComp.weight;
211 const float w2 = newComp.weight;
213 const float k = 1. / (w1 + w2);
214 const Eigen::VectorXf d = x1 - x2;
216 const Eigen::VectorXf
mean = k * (w1 * x1 + w2 * x2);
217 const Eigen::MatrixXf cov = k * (w1 * p1 + w2 * p2 + k * w1 * w2 * d * d.transpose());
219 GaussianMixtureComponent result;
221 result.weight = w1 + w2;