46 EntityFusionMethod(
"GaussianMixturePositionFusion"), agingFactor(agingFactor), pruningThreshold(pruningThreshold),
47 associationMethod(assMethod)
61 EntityBasePtr
initEntity(
const EntityBasePtr& updateEntity, const ::Ice::Current& = Ice::emptyCurrent)
override
67 return EntityBasePtr();
70 MultivariateNormalDistributionBasePtr posGaussian = instance->getPositionUncertainty();
74 ObjectInstancePtr fusedInstance = ObjectInstancePtr::dynamicCast(instance->ice_clone());
77 fusedInstance->setId(
"");
82 fusedInstance->getPositionAttribute()->setValueWithUncertainty(instance->getPositionAttribute()->getValue(), posGM);
98 EntityBasePtr
fuseEntity(
const EntityBasePtr& oldEntity,
const EntityBasePtr& newEntity, const ::Ice::Current& = Ice::emptyCurrent)
override
100 ObjectInstancePtr fusedInstance = ObjectInstancePtr::dynamicCast(oldEntity->ice_clone());
101 EntityAttributeBasePtr posAttr = fusedInstance->getPositionAttribute();
109 posGM->scaleComponents(agingFactor);
111 MultivariateNormalDistributionBasePtr newUncertainty = newInstance->getPositionUncertainty();
112 GaussianMixtureComponent newComp;
113 newComp.gaussian = newUncertainty;
118 int associatedCompIndex = associationMethod->getAssociatedComponentIndex(normGM, newComp);
120 if (associatedCompIndex >= 0)
122 GaussianMixtureComponent associatedComp = posGM->getComponent(associatedCompIndex);
123 GaussianMixtureComponent associatedNormComp = normGM->getComponent(associatedCompIndex);
124 GaussianMixtureComponent newNormComp = normGM->getComponent(posGM->size() - 1);
125 GaussianMixtureComponent fusedComp = fuseGaussianComponents(associatedNormComp, newNormComp);
126 fusedComp.weight = newComp.weight + associatedComp.weight;
127 posGM->setComponent(associatedCompIndex, fusedComp);
131 posGM->addComponent(newComp);
135 if (pruningThreshold > 0)
137 posGM->pruneComponents(pruningThreshold);
144 GaussianMixtureComponent modalComp = posGM->getModalComponent();
146 if (modalComp.gaussian)
150 fusedInstance->setPosition(posMean);
151 fusedInstance->getPositionAttribute()->setValueWithUncertainty(fusedInstance->getPositionAttribute()->getValue(), posGM);
152 return fusedInstance;
156 return EntityBasePtr();
161 return EntityBasePtr();
167 float pruningThreshold;
168 GaussianMixtureAssociationMethodBasePtr associationMethod;
170 GaussianMixtureComponent fuseGaussianComponents(
const GaussianMixtureComponent& oldComp,
const GaussianMixtureComponent& newComp)
175 const Eigen::VectorXf x1 = oldGaussian->toEigenMean();
176 const Eigen::VectorXf x2 = newGaussian->toEigenMean();
177 const Eigen::MatrixXf p1 = oldGaussian->toEigenCovariance();
178 const Eigen::MatrixXf p2 = newGaussian->toEigenCovariance();
180 const float w1 = oldComp.weight;
181 const float w2 = newComp.weight;
183 const float k = 1. / (w1 + w2);
184 const Eigen::VectorXf d = x1 - x2;
186 const Eigen::VectorXf
mean = k * (w1 * x1 + w2 * x2);
187 const Eigen::MatrixXf cov = k * (w1 * p1 + w2 * p2 + k * w1 * w2 * d * d.transpose());
189 GaussianMixtureComponent result;
191 result.weight = w1 + w2;