Пример #1
0
        public ProductClasses(InputDistortionProbabilities inputDistProb, Gprobabilites[][] bitProbabilities, int lenInput)
        {
            _correctValueProbability = new double[2][];
            int lenF2Result = bitProbabilities[0].Length;

            _correctValueProbability[1] = _correctValueProbability[0] = new double[lenInput];
            AllocateDeterminedDistortionProbalilitiesVectors(ref _autoCorrectionValueProbability, lenInput);
            AllocateDeterminedDistortionProbalilitiesVectors(ref _distortedValueProbability, lenInput);
            const int BinaryDigitStates = 2;

            double[][] digitDistortionProbability = new double[BinaryDigitStates][]; // temp variable
            digitDistortionProbability[0] = inputDistProb.DistortionToZeroProbability;
            digitDistortionProbability[1] = inputDistProb.DistortionToOneProbability;
            _probalityZero    = new double[2][];
            _probalityZero[0] = new double[lenInput];
            _probalityZero[1] = new double[lenInput];
            // set gxx values for bits 1..t
            for (int i = 0; i < lenInput - lenF2Result; i++)
            {
                _correctValueProbability[0][i] = inputDistProb.CorrectValueProbability[i];
                _probalityZero[0][i]           = inputDistProb.ZeroProbability[i];
                _probalityZero[1][i]           = 1 - inputDistProb.ZeroProbability[i];
                for (int digit = 0; digit < BinaryDigitStates; digit++)
                {
                    // gcaij = g(const_(aij)) * p_aij
                    _autoCorrectionValueProbability[digit][i] = digitDistortionProbability[digit][i];// *ProbabilityZeroAndOne(digit, i);

                    // geaij = (g(const_(not aij)) + p inv ) * p_aij
                    _distortedValueProbability[digit][i] = (digitDistortionProbability[BinaryDigitStates - digit - 1][i] //digitDistortionProbability[!digit][i]
                                                            + inputDistProb.DistortionToInverseProbability[i]);          // *ProbabilityZeroAndOne(digit, i);
                }
            }
            // set gxx values for bits t+1..n
            int indexbitProb = 0;

            for (int i = lenInput - lenF2Result; i < lenInput; i++)
            {
                _probalityZero[0][i]           = _probalityZero[1][i] = 1.0;
                _correctValueProbability[0][i] = bitProbabilities[0][indexbitProb].G0;
                for (int digit = 0; digit < BinaryDigitStates; digit++)
                {
                    // gcaij = g(const_(aij)) * p_aij
                    _autoCorrectionValueProbability[digit][i] = (bitProbabilities[digit][indexbitProb].Gc + bitProbabilities[digit][indexbitProb].Gce);// *ProbabilityZeroAndOne(digit, i);

                    // geaij = (g(const_(not aij)) + p inv ) * p_aij
                    _distortedValueProbability[digit][i] = bitProbabilities[digit][indexbitProb].Gee;// *ProbabilityZeroAndOne(digit, i);
                }
                double check = _correctValueProbability[0][i] + _autoCorrectionValueProbability[0][i] + _autoCorrectionValueProbability[1][i] +
                               _distortedValueProbability[0][i] + _distortedValueProbability[1][i];
                if (check > 1.0001)
                {
                    throw new Exception("Oh no!");
                }
                indexbitProb++;
            }
        }
Пример #2
0
        private void button4_Click(object sender, EventArgs e)
        {
            /*int digitsInput = 4, digitsOutput = 1;
             * double[] distortionto1Probability = { 0.0, 0.0, 0.0, 0.0 };
             * double[] distortionto0Probability = { 0.0, 0.0, 0.0, 0.0 };
             * double[] distortiontoInverseProbability = { 0.5, 0.5, 0.5, 0.5 };
             * double[] zeroProbability = { 0.5, 0.5, 0.5, 0.5 };
             * string[] func = new string[1];
             * func[0] = "(x[0] ^ x[1]) ^ (x[2] ^ x[3])";
             * var f = new BooleanFunctionAnalytic(digitsInput, digitsOutput, func);
             * f.SetDistortionProbabilitiesVectors(distortionto0Probability, distortionto1Probability, distortiontoInverseProbability);
             * ProbabilitiesGxyCalc pGxy = new ProbabilitiesGxyCalc(f, zeroProbability);
             * var actual = pGxy.GetGprobabilitesResult(new BitArray(digitsOutput, true));
             * var actual1 = pGxy.GetGprobabilitesResult(new BitArray(digitsOutput, false));
             * var Ge = actual1.Gce + actual.Gce + actual1.Gee + actual.Gee;
             * var G = Ge + actual.G0 + actual.Gc + actual1.Gc;
             * string[] func1 = new string[1];
             * string[] func2 = new string[1];
             * func1[0] = "(x[0] ^ x[1]) ^ x[2]";
             * func2[0] = "x[0] ^ x[1]";
             * var digitsInputf1 = 3;
             * var digitsInputf2 = 2;
             * var f1 = new BooleanFunctionAnalytic(digitsInputf1, digitsOutput, func1);
             * var f2 = new BooleanFunctionAnalytic(digitsInputf2, digitsOutput, func2);
             * InputDistortionProbabilities inpDist =
             *  new InputDistortionProbabilities(distortionto0Probability, distortionto1Probability,
             *      distortiontoInverseProbability, zeroProbability);
             * ProbGxyCalcSuperposition pSprPos = new ProbGxyCalcSuperposition(f1, f2, inpDist);
             * var actual2 = pSprPos.GetGprobabilitesResult(new BitArray(digitsOutput, true));
             * var actual3 = pSprPos.GetGprobabilitesResult(new BitArray(digitsOutput, false));*/
            var f1 = new BooleanFunctionDelegate(6, 1, f6);
            var f2 = new BooleanFunctionDelegate(5, 1, f5);
            DistortionProbTextReader     reader  = new DistortionProbTextReader(@"D:\DiplomInput\InputDistortion10bitFANDOR.txt");
            InputDistortionProbabilities inpDist =
                reader.GetDistortionProb();
            ProbGxyCalcSuperposition pSprPos = new ProbGxyCalcSuperposition(f1, f2, inpDist);
            var actual2 = pSprPos.GetGprobabilitesResult(new BitArray(1, true));
            var actual3 = pSprPos.GetGprobabilitesResult(new BitArray(1, false));
            var GeS     = actual2.Gce + actual3.Gce + actual2.Gee + actual3.Gee;
            var GS      = GeS + actual2.G0 + actual2.Gc + actual3.Gc;
            var f       = new BooleanFunctionDelegate(10, 1, f10);

            f.SetDistortionProbabilitiesVectors(inpDist);
            ProbabilitiesGxyCalc pGxy = new ProbabilitiesGxyCalc(f, inpDist.ZeroProbability);
            //var actual = pGxy.GetGprobabilitesResult(new BitArray(1, true));
            //var actual1 = pGxy.GetGprobabilitesResult(new BitArray(1, false));
            //var Ge = actual1.Gce + actual.Gce + actual1.Gee + actual.Gee;
            //var G = Ge + actual.G0 + actual.Gc + actual1.Gc;
        }
Пример #3
0
        public ProbGxyCalcSuperposition(BooleanFuntionWithInputDistortion truthTable1,
                                        BooleanFuntionWithInputDistortion truthTable2, InputDistortionProbabilities inputDistortionProb)
        {
            _f1 = truthTable1;
            _f2 = truthTable2;
            if (inputDistortionProb.ZeroProbability.Length != _f1.InputNumberOfDigits + _f2.InputNumberOfDigits - _f2.OutputNumberOfDigits)
            {
                throw new Exception("Size of probalityZero array don't fit the InputNumberOfDigits of truth table composition.");
            }
            _inputDistortionProb = inputDistortionProb;

            // copy distortion for f2
            LoadDistortionToBoolFunction(_f2, _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits, _f2.InputNumberOfDigits);
            LoadDistortionToBoolFunction(_f1, 0, _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits);
            _probCalcF1 = null;
        }
Пример #4
0
 private void LoadDistortionToBoolFunction(BooleanFuntionWithInputDistortion f, InputDistortionProbabilities inputDistortionProb)
 {
     f.SetDistortionProbabilitiesVectors(inputDistortionProb.DistortionToZeroProbability,
                                         inputDistortionProb.DistortionToOneProbability, inputDistortionProb.DistortionToInverseProbability);
 }
Пример #5
0
 private void SetDistProb(InputDistortionProbabilities inpDistProb)
 {
     _inpDistProb = inpDistProb;
 }