Пример #1
0
 // Get probability of distorted (0||1) result == Result without distortion
 public Gprobabilites GetGprobabilitesResult(BitArray result)
 {
     if (null == _probCalcF1)
     {
         CalcF2ProbabilitiesGxyNew();
     }
     return(_probCalcF1.GetGprobabilitesResult(result));
 }
Пример #2
0
        private void CalcF2ProbabilitiesGxyNew()
        {
            if (null != _probCalcF1)
            {
                return;
            }
            int resultsCount = 1 << _f2.OutputNumberOfDigits;

            Gprobabilites[] boolFunc2Gp     = new Gprobabilites[resultsCount];
            double[]        f2ProbalityZero = new double[_f2.InputNumberOfDigits];

            for (int i = 0; i < f2ProbalityZero.Length; i++)
            {
                f2ProbalityZero[i] = _inputDistortionProb.ZeroProbability[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits];
            }

            var f2Calc = new ProbabilitiesGxyCalc(_f2, f2ProbalityZero);

            double[] probabilityZeroF1 = new double[_f1.InputNumberOfDigits];
            // copy input zero probability for function f1 in range [1,..,t]
            for (int i = 0; i < _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits; i++)
            {
                probabilityZeroF1[i] = _inputDistortionProb.ZeroProbability[i];
            }
            for (int i = 0; i < _f2.OutputNumberOfDigits; i++)
            {
                probabilityZeroF1[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits] = 0.0;
            }
            // create Gprobabilities for a separate bit of f2 function result
            const int BinaryDigitState = 2;

            Gprobabilites[][] digitSeparateProb = new Gprobabilites[BinaryDigitState][];
            for (int i = 0; i < BinaryDigitState; i++)
            {
                digitSeparateProb[i] = new Gprobabilites[f2Calc.OutputNumberOfDigits()];
            }
            // calc results probabilities
            int      indexBoolFunc2Gp = 0;
            BitArray resultVect       = new BitArray(_f2.OutputNumberOfDigits, false); // 00...0

            do
            {
                boolFunc2Gp[indexBoolFunc2Gp] = f2Calc.GetGprobabilitesResult(resultVect);
                // calc G prob of separate bits of result
                for (int i = 0; i < digitSeparateProb[0].Length; i++)
                {
                    int digit = resultVect[i] ? 1 : 0;
                    digitSeparateProb[digit][i].G0   = boolFunc2Gp[indexBoolFunc2Gp].G0;
                    digitSeparateProb[digit][i].Gc  += boolFunc2Gp[indexBoolFunc2Gp].Gc;
                    digitSeparateProb[digit][i].Gce += boolFunc2Gp[indexBoolFunc2Gp].Gce;
                    digitSeparateProb[digit][i].Gee += boolFunc2Gp[indexBoolFunc2Gp].Gee;
                }
                ++indexBoolFunc2Gp;
            } while (BooleanFuntionWithInputDistortion.IncrementOperand(resultVect));
            var prodClasses = new ProductClasses(_inputDistortionProb, digitSeparateProb, _f1.InputNumberOfDigits);

            _probCalcF1 = new ProbabilitiesGxyCalc(_f1, prodClasses);
        }
Пример #3
0
        private void CalcF2ProbabilitiesGxy()
        {
            if (null != _probCalcF1)
            {
                return;
            }
            int resultsCount = 1 << _f2.OutputNumberOfDigits;

            Gprobabilites[] boolFunc2Gp     = new Gprobabilites[resultsCount];
            double[]        f2ProbalityZero = new double[_f2.InputNumberOfDigits];

            for (int i = 0; i < f2ProbalityZero.Length; i++)
            {
                f2ProbalityZero[i] = _inputDistortionProb.ZeroProbability[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits];
            }

            var f2Calc = new ProbabilitiesGxyCalc(_f2, f2ProbalityZero);

            double[] probabilityZeroF1 = new double[_f1.InputNumberOfDigits];
            // copy input zero probability for function f1 in range [1,..,t]
            for (int i = 0; i < _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits; i++)
            {
                probabilityZeroF1[i] = _inputDistortionProb.ZeroProbability[i];
            }
            for (int i = 0; i < _f2.OutputNumberOfDigits; i++)
            {
                probabilityZeroF1[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits] = 0.0;
            }
            // get zero probability
            int      indexBoolFunc2Gp = 0;
            BitArray resultVect       = new BitArray(_f2.OutputNumberOfDigits, false); // 00...0

            do
            {
                boolFunc2Gp[indexBoolFunc2Gp] = f2Calc.GetGprobabilitesResult(resultVect);

                // calc input zero probability for function f1 in range [t+1,..., t+_f2.OutputNumberOfDigits]
                for (int i = 0; i < _f2.OutputNumberOfDigits; i++)
                {
                    if (!resultVect[i]) // if res[i] == 0
                    {
                        probabilityZeroF1[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits] +=
                            boolFunc2Gp[indexBoolFunc2Gp].SumCorrectionAndError();  // sum without G0
                    }
                }
                ++indexBoolFunc2Gp;
            } while (BooleanFuntionWithInputDistortion.IncrementOperand(resultVect));
            // add G0
            for (int i = 0; i < _f2.OutputNumberOfDigits; i++)
            {
                probabilityZeroF1[i + _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits] +=
                    boolFunc2Gp[0].G0 / _f2.Length;
            }
            // get distortion prob
            const int DistortionTypes = 3;

            double[][] distProb = new double[DistortionTypes][];
            for (int r = 0; r < distProb.Length; r++)
            {
                distProb[r] = new double[_f1.InputNumberOfDigits];
                for (int i = 0; i < _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits; i++)
                {
                    distProb[r][i] = _f1.ProbabilityVectors[r + 1][i];
                }
                int indexBase = _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits;
                for (int i = 0; i < _f2.OutputNumberOfDigits; i++)
                {
                    distProb[r][indexBase + i] = 0;
                }
            }
            indexBoolFunc2Gp = 0;
            resultVect       = new BitArray(_f2.OutputNumberOfDigits, false); // 00...0
            do
            {
                int indexBase = _f1.InputNumberOfDigits - _f2.OutputNumberOfDigits;
                for (int i = 0; i < resultVect.Length; i++)
                {
                    double bitProb = 0.0;
                    if (resultVect[i]) // distortionTo1
                    {
                        bitProb = 1 - probabilityZeroF1[indexBase + i];
                        distProb[1][i + indexBase] += (boolFunc2Gp[indexBoolFunc2Gp].Gc + boolFunc2Gp[indexBoolFunc2Gp].Gce);// / bitProb;
                    }
                    else // distortionTo0
                    {
                        bitProb = probabilityZeroF1[indexBase + i];
                        distProb[0][i + indexBase] += (boolFunc2Gp[indexBoolFunc2Gp].Gc + boolFunc2Gp[indexBoolFunc2Gp].Gce); // / bitProb;
                    }
                    distProb[DistortionTypes - 1][i + indexBase] += boolFunc2Gp[indexBoolFunc2Gp].Gee;                        // / (1 - bitProb);
                }
                ++indexBoolFunc2Gp;
            } while (BooleanFuntionWithInputDistortion.IncrementOperand(resultVect));
            // Set zero prob and dist prob to _f1
            _f1.DistortionToZeroProbability    = distProb[0];
            _f1.DistortionToOneProbability     = distProb[1];
            _f1.DistortionToInverseProbability = distProb[2];
            _f1.CorrectValueProbability        = null;
            double[]   correctValueProbability        = new double[_f1.InputNumberOfDigits];
            double[][] autoCorrectionValueProbability = null;
            double[][] distortedValueProbability      = null;
            AllocateDeterminedDistortionProbalilitiesVectors(ref autoCorrectionValueProbability);
            AllocateDeterminedDistortionProbalilitiesVectors(ref distortedValueProbability);


            _probCalcF1 = new ProbabilitiesGxyCalc(_f1, probabilityZeroF1);
        }