protected ComputeKsi ( int index, double fwd, double bwd, double scaling ) : void | ||
index | int | The index of the observation in the input training data. |
fwd | double | The matrix of forward probabilities for the observation. |
bwd | double | The matrix of backward probabilities for the observation. |
scaling | double | The scaling vector computed in previous calculations. |
return | void |
protected override void ComputeKsi(int index, double[,] fwd, double[,] bwd, double[] scaling)
{
int states = model.States;
double[,] A = model.Transitions;
IDistribution[] B = model.Emissions;
double[][] sequence = continuousObservations[index];
double[][,] ksi = Ksi[index];
for (int t = 0; t < ksi.Length - 1; t++)
{
double s = 0;
double c = scaling[t + 1];
double[,] ksit = ksi[t];
double[] x = sequence[t + 1];
for (int k = 0; k < states; k++)
for (int l = 0; l < states; l++)
s += ksit[k, l] = c*fwd[t, k]*A[k, l]*bwd[t + 1, l]*B[l].ProbabilityFunction(x);
if (s != 0) // Scaling
{
for (int k = 0; k < states; k++)
for (int l = 0; l < states; l++)
ksit[k, l] /= s;
}
}
}