Vector classProbs = (currentState == null) ? this.marginalClassProbs :
this.classTransProbs.getColumn(currentClass);
currentClass = DiscreteSamplingUtil.sampleIndexFromProbabilities(random, classProbs);
KalmanFilter currentFilter = this.stateFilters.get(currentClass);
if (currentState == null) {
currentState = currentFilter.createInitialLearnedObject().sample(random);
} else {
final Matrix G = currentFilter.getModel().getA();
Matrix modelCovSqrt = CholeskyDecompositionMTJ.create(
(DenseMatrix) currentFilter.getModelCovariance()).getR();
currentState = MultivariateGaussian.sample(G.times(currentState), modelCovSqrt, random);
}
currentState.plusEquals(currentFilter.getModel().getB().times(
currentFilter.getCurrentInput()));
final Matrix F = currentFilter.getModel().getC();
Vector observationMean = F.times(currentState);
Matrix measurementCovSqrt = CholeskyDecompositionMTJ.create(
(DenseMatrix) currentFilter.getMeasurementCovariance()).getR();
Vector observation = MultivariateGaussian.sample(observationMean,
measurementCovSqrt, random);
results.add(new SimHmmObservedValue<Vector, Vector>(i, currentClass,
currentState.clone(), observation));