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;
double[,] B = model.Emissions;
int[] sequence = discreteObservations[index];
double[][,] ksi = Ksi[index];
for (int t = 0; t < sequence.Length - 1; t++)
{
double s = 0;
double c = scaling[t + 1];
int x = sequence[t + 1];
double[,] ksit = ksi[t];
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, x];
if (s != 0) // Scaling
{
for (int k = 0; k < states; k++)
for (int l = 0; l < states; l++)
ksit[k, l] /= s;
}
}
}
}