コード例 #1
0
ファイル: Lab1.cs プロジェクト: oshipka/InformationTheory
        public static void Task2()
        {
            //HXandY(matr_t2);
            //HXifY(PXifY(matr_t2), px(matr_t2));
            var pxT2 = Px(MatrT2);
            var pyT2 = Py(MatrT2);

            Console.WriteLine("H(X)");
            H(pxT2, out var hX);
            Console.WriteLine("H(Y)");
            H(pyT2, out var hY);

            Console.WriteLine("ro_x");
            Ro(hX, Hmax(3), out _);
            Console.WriteLine("ro_y");
            Ro(hY, Hmax(3), out _);

            Console.WriteLine("P(Y|X)");
            var pYifX = Lab1.PYifX(MatrT2);

            HYifX(pYifX, pxT2);
            var hxandy = HXandY(MatrT2);

            AvgInfo(hX, hY, hxandy);
        }
コード例 #2
0
ファイル: Lab2.cs プロジェクト: oshipka/InformationTheory
        private static double I(double[][] matrix_pxandy)
        {
            var px = Lab1.Px(matrix_pxandy);

            Lab1.H(px, out var Hx);
            var py = Lab1.Py(matrix_pxandy);

            Lab1.H(py, out var Hy);
            var hXandY = Lab1.HXandY(matrix_pxandy);
            var res    = Hx + Hy - hXandY;

            Console.WriteLine("I(X;Y) = " + Hx + " + " + Hy + " - " + hXandY + " = " + res);
            return(res);
        }
コード例 #3
0
        private static double RelativeDifference(List <Symbol> coded, int wordLength)
        {
            PullLists(coded, out var pi, out var li);
            var l = AverageLength(pi, li) / wordLength;

            Lab1.H(pi, out var entr);
            var res = ((l - entr) / entr) * 100.0;

            Console.WriteLine("((" +
                              Math.Round(l, 3) +
                              "-" +
                              Math.Round(entr, 3) +
                              ")/" +
                              entr +
                              ")*100%=" +
                              Math.Round(res, 3) +
                              "%");
            return(res);
        }
コード例 #4
0
ファイル: Lab2.cs プロジェクト: oshipka/InformationTheory
        public static void Task1()
        {
            Console.WriteLine("I(X;Y)");
            var I = Lab2.I(matrix_t1);

            Console.WriteLine("V");
            var v = Lab2.V(v0_t1, I);

            Console.WriteLine("P(X|Y)");
            var pXifY = Lab1.Pxify(matrix_t1, Lab1.Py(matrix_t1));

            Console.WriteLine("P(Y|X)");
            var pYifX = Lab1.PYifX(matrix_t1);

            Console.WriteLine("C");
            var c = Lab2.C(v0_t1, pYifX);

            string[] val = { "I(X;Y)", "V", "C" };
            AnsverTable(val, new[] { I, v, c });
        }
コード例 #5
0
ファイル: Lab2.cs プロジェクト: oshipka/InformationTheory
        private static double C(int v0, double[][] matrix_pyifx)
        {
            var max     = Lab1.Hmax(3);
            var res     = 0.0;
            var precalc = max + " + ";
            var calc    = max + " + ";

            for (int i = 0; i < 3; i++)
            {
                var val    = matrix_pyifx[1][i];
                var interm = val * Math.Log(val, 2);
                precalc += val + "log2 " + val + " + ";
                calc    += interm + " + ";
                res     += interm;
            }

            res += max;
            res *= v0;
            Console.WriteLine("C =\n " + v0 + "*(" + precalc + ")=\n " + v0 + "*(" + calc + ")=" + Math.Round(res, 3));
            return(res);
        }
コード例 #6
0
ファイル: Lab1.cs プロジェクト: oshipka/InformationTheory
        internal static double[][] PYifX(double[][] pXandY)
        {
            var result        = new double[pXandY.Length][];
            var px            = Lab1.Px(pXandY);
            var precalculated = "";
            var calculated    = "";
            var len           = pXandY.Length;

            for (var i = 0; i < len; i++)
            {
                result[i] = new double[len];
                for (var j = 0; j < len; j++)
                {
                    var probability = Pxify(pXandY[i][j], px[i]);
                    precalculated += pXandY[i][j] + " / " + px[i] + "\t";
                    calculated    += Math.Round(probability, 2) + "\t";
                    result[i][j]   = probability;
                }

                precalculated += "\n";
                calculated    += "\n";
            }

            Console.WriteLine("P(Y|X) = ");
            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len; j++)
                {
                    Console.Write("\t" + Math.Round(result[i][j], 2));
                }
                Console.Write("\n");
            }

            Console.WriteLine("P(Y|X) = \n" + precalculated + "\n=\n" + calculated);
            return(result);
        }