Hi Marcel,
No problem, thanks for the update. Yes, it's true that noise estimation is not straightforward.
Anyway, everything works smoothly as before with this change.
When do you plan to make this online course available ?
I have a question though, that may be Scala-related: could you have a look at the codes below please ?
In fact, I tried to re-factor the codes of the Tutorial 15 and put each case class in a separate Scala file (e.g. CachedEvaluator.scala, etc.) . But I don't understand why I got nothing at all compared to having all those case classes in a single script. I mean I got nothing because all the parameters are not updated during iteration consumption. Is this related to bad class instantiation ? To memory issue (though I used CachedEvaluator) ? ... Sorry to bother you with that but I have been struggling with this for a few days and I don't understand what is happening ...
Here are the codes:
===================
al modelLmIds = modelLms.map(l => model.mean.pointSet.pointId(l.point).get)
val targetPoints = targetLms.map(l => l.point)
val landmarkNoiseVariance = 9.0
val uncertainty = MultivariateNormalDistribution(
DenseVector.zeros[Double](3),
DenseMatrix.eye[Double](3) * landmarkNoiseVariance
)
val correspondences = modelLmIds
.zip(targetPoints)
.map(modelIdWithTargetPoint => {
val (modelId, targetPoint) = modelIdWithTargetPoint
(modelId, targetPoint, uncertainty)
})
/** prior and likelihood */
val corrEval = CorrespondenceEvaluator(model, correspondences)
val likelihoodEvaluator = CachedEvaluator(CorrespondenceEvaluator(model, correspondences))
val priorEvaluator = CachedEvaluator(PriorEvaluator(model))
val posteriorEvaluator = ProductEvaluator(priorEvaluator, likelihoodEvaluator)
/** Proposal generator */
val iShape = ShapeUpdateProposal(model.rank, 0.1)
val iRotation = RotationUpdateProposal(0.01)
val iTranslation = TranslationUpdateProposal(1.0)
val generator = MixtureProposal.fromProposalsWithTransition(
(0.6, iShape),
(0.2, iRotation),
(0.2, iTranslation)
)
/** Building the Markov Chain */
val initialParameters = Parameters(
EuclideanVector(0, 0, 0),
(0.0, 0.0, 0.0),
DenseVector.zeros[Double](model.rank),
0.0
)
val initialSample = Sample("initial", initialParameters, computeCenterOfMass(model.mean))
val chain = MetropolisHastings(generator, posteriorEvaluator)
val logger = new Logger()
val mhIterator = chain.iterator(initialSample, logger)
// Visualize
val samplingIterator = for ((sample, iteration) <- mhIterator.zipWithIndex) yield {
println("iteration " + iteration)
if (iteration % 500 == 0) {
modelView.shapeModelTransformationView.shapeTransformationView.coefficients = sample.parameters.modelCoefficients
modelView.shapeModelTransformationView.poseTransformationView.transformation = sample.poseTransformation
}
sample
}
val samples = samplingIterator.slice(1000, 10000).toIndexedSeq
val bestSample = samples.maxBy(posteriorEvaluator.logValue)
val bestFit = model.instance(bestSample.parameters.modelCoefficients).transform(bestSample.poseTransformation)
======
Thank you very much,
Best regards
Maia