Skip to content

Instantly share code, notes, and snippets.

@0xdeafbeef
Created January 22, 2018 14:26
Show Gist options
  • Save 0xdeafbeef/5a35fc5f50b507b39089d3d39a79e969 to your computer and use it in GitHub Desktop.
Save 0xdeafbeef/5a35fc5f50b507b39089d3d39a79e969 to your computer and use it in GitHub Desktop.
Finds minimum code distance in BCH codes
public class MinDistanceSolver {
public static void main(String[] args) {
double currentRowState, p = 2.555 * Math.pow(10, -3), q = 1 - p, pTransformation = Math.pow(10, -11); // Данные
int dMinimum = 1, n = 31, k = 1; //Данные
double pInhibition; // Данные
System.out.println("-------------------------------------------------------"); //декоратор
do { //расчет Д минимум
System.out.print(dMinimum + " ");
currentRowState = combinator(n, dMinimum) * Math.pow(p, dMinimum) * Math.pow(q, n - dMinimum) * (((dMinimum + 1) * q) / ((dMinimum + 1) - ((n + 1) * p)));
System.out.println(currentRowState);
dMinimum++;
} while (pTransformation < currentRowState);
System.out.println("dminimum = " + (dMinimum - 1)); // dMinimum - 1 из-за свойства цикла
System.out.println("-------------------------------------------------------"); //декоратор
double sum = 0, epsilon = 0.01;
do { //расчет числа к, используемого при вычислении бинома ньютона.
double currentInternalSum = combinator(n, k) * Math.pow(-1, k) * Math.pow(p, k);
sum += currentInternalSum; //вычисление
currentRowState = (combinator(n, k + 1) * Math.pow(-1, k + 1) * Math.pow(p, k + 1)) / (1 + sum);
k++;
System.out.println("Current state = " + currentRowState);
} while (Math.abs(currentRowState) > epsilon);
System.out.println("K = " + (k - 1)); //k-1 из-за свойства цикла
System.out.println("-------------------------------------------------------");//декоратор
System.out.printf("Вероятность правильного приема " + "%.4f", Util.binomial(k, n, p)); // расчет вероятности правильного приема при помощи бинома ньютона.
System.out.println();
pInhibition = 1 - Util.binomial(k, n, p) - pTransformation; //Расчет вероятночти подавления
System.out.printf("Вероятность подавления равна " + "%.4f", pInhibition);
System.out.println();
System.out.println("-------------------------------------------------------"); //декоратор
}
static double combinator(int n, int k) { /** documentation функция расчитывает число сочетаний, возвращает число не более 1.7*10^308 */
return Util.factorial(n).divide(Util.factorial(n - k).multiply(Util.factorial(k))).doubleValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment