public static double[,] ListOfCoeffs(double[,] coeffs) { double[] Scale2 = Haar.Scale2To1DCoeff(coeffs); double[,] Scale1 = Haar.Scale1To1DCoeff(coeffs); double[,] Scale = new double[Scale2.Length, 5]; for (int i = 0; i < Scale2.Length; i++) { Scale[i, 0] = Scale2[i]; Scale[i, 1] = Scale1[i, 0]; Scale[i, 2] = Scale1[i, 1]; Scale[i, 3] = Scale1[i, 2]; Scale[i, 4] = Scale1[i, 3]; } return(Scale); }
/// <summary> /// Calculate likelihood probability of child node in state n given the parent node in state m. /// P(n|m) , n = child node and m = parent node. /// Create A Matrix that contain: /// [P(n=1|m=1) P(n=2|m=1)] -> [ pos=1 pos=2 ] /// [P(n=1|m=2) P(n=2|m=2)] [ pos=3 pos=4 ] /// The nature of Child Hidden States are that 1 & 3 always same, and 2 & 4 always same.(still in doubt) /// </summary> /// <param name="coeffs">Wavelet Coefficients</param> /// <param name="pos">Position of child node for each parent -> pos ={1,2,3,4}</param> /// <param name="m">Hidden state of Parent node</param> /// <param name="n">Hidden state of Child node</param> /// <returns></returns> public static double TransitionProbability(double[,] coeffs, /*int pos,*/ int n, int m) { double[,] hiddenstates = GetHiddenStateValue(coeffs); // Calculate number of parent node with state 1 or 2 double rootpmf1 = StateProbability2(hiddenstates, 2, 1); double rootpmf2 = StateProbability2(hiddenstates, 2, 2); double NumOfRootm1 = (double)rootpmf1 * (double)(((coeffs.GetLength(0) * coeffs.GetLength(1)) / 16) * 3); //Number of parent node whose m = 1 double NumOfRootm2 = (double)rootpmf2 * (double)(((coeffs.GetLength(0) * coeffs.GetLength(1)) / 16) * 3); //Number of parent node whose m = 2 double[] Scale2 = Haar.Scale2To1DCoeff(hiddenstates); double[,] Scale1 = Haar.Scale1To1DCoeff(hiddenstates); double[,] Scale = new double[Scale2.Length, 5]; for (int i = 0; i < Scale2.Length; i++) { Scale[i, 0] = Scale2[i]; Scale[i, 1] = Scale1[i, 0]; Scale[i, 2] = Scale1[i, 1]; Scale[i, 3] = Scale1[i, 2]; Scale[i, 4] = Scale1[i, 3]; } ///Calculating Transition probability int c1 = 0; int c2 = 0; int c3 = 3; int c4 = 4; if (n == 1 && m == 1) { for (int i = 0; i < Scale.GetLength(0); i++) { for (int j = 1; j < Scale.GetLength(1); j++) { if (Scale[i, j] == 1 && Scale[i, 0] == 1) { c1++; } } } double transitionProb = (double)c1 / (double)NumOfRootm1; return(transitionProb); } else if (n == 2 && m == 1) { for (int i = 0; i < Scale.GetLength(0); i++) { for (int j = 1; j < Scale.GetLength(1); j++) { if (Scale[i, j] == 2 && Scale[i, 0] == 1) { c2++; } } } double transitionProb = (double)c2 / (double)NumOfRootm1; return(transitionProb); } else if (n == 1 && m == 2) { for (int i = 0; i < Scale.GetLength(0); i++) { for (int j = 1; j < Scale.GetLength(1); j++) { if (Scale[i, j] == 1 && Scale[i, 0] == 2) { c3++; } } } double transtitionProb = (double)c3 / (double)NumOfRootm2; return(transtitionProb); } else { for (int i = 0; i < Scale.GetLength(0); i++) { for (int j = 1; j < Scale.GetLength(1); j++) { if (Scale[i, j] == 2 && Scale[i, 0] == 2) { c4++; } } } double transtitionProb = (double)c4 / (double)NumOfRootm2; return(transtitionProb); } }