Exemplo n.º 1
0
    static void testBitvectorInduction()
    {
        SlowBitvector testBitvector = new SlowBitvector();

        //testBitvector.vector = new bool[]{false, true, false, false};
        testBitvector.vector = new List <bool>()
        {
            false, true, false, true,
        };

        induction.BitvectorInduction.predictNextBit(testBitvector, 1);
    }
Exemplo n.º 2
0
    /*
     * public static bool equals(SlowBitvector a, SlowBitvector b) {
     *  if (a.vector.Count != b.vector.Count) {
     *      return false;
     *  }
     *
     *  for (int i = 0; i < a.vector.Count; i++) {
     *      if (a.vector[i] != b.vector[i]) {
     *          return false;
     *      }
     *  }
     *
     *  return true;
     * }
     */

    public SlowBitvector subvector(uint startIndex, uint endIndex)
    {
        Debug.Assert(endIndex >= startIndex, "Negative length is not valid!");

        SlowBitvector result = new SlowBitvector();

        result.vector = new List <bool>(new bool[endIndex - startIndex]);

        int iResult = 0;

        for (int i = (int)startIndex; i < (int)endIndex; i++)
        {
            result.vector[iResult] = vector[i];
            iResult++;
        }

        return(result);
    }
Exemplo n.º 3
0
        // for debugging
        private static string debugBitvector(SlowBitvector vector)
        {
            StringBuilder sb = new StringBuilder();

            foreach (bool iterationValue in vector.vector)
            {
                if (iterationValue)
                {
                    sb.Append("1");
                }
                else
                {
                    sb.Append("0");
                }
            }

            return(sb.ToString());
        }
Exemplo n.º 4
0
    static void testBitvectorInductionSequence1()
    {
        SlowBitvector testBitvector = new SlowBitvector();

        /*
         * testBitvector.vector = new List<bool>() {
         *  true, true, false, false,
         *  };
         */


        testBitvector.vector = new List <bool>()
        {
            false, false, false,
            false, false, true,
            false, true, false,
            false, true, true,

            true, false, false,
            true, false, true,
            true, true, false,
        };

        bool predictedBit;

        induction.BitvectorInduction.Prediction prediction;

        for (int i = 0; i < 1; i++)
        {
            prediction = induction.BitvectorInduction.predictNextBit(testBitvector, 1);

            predictedBit = prediction.trueCounter > prediction.falseCounter;
            Console.WriteLine("predicted {0}", predictedBit);

            testBitvector.vector.Add(predictedBit);
        }

        int breakHere = 1;
    }
Exemplo n.º 5
0
        private static bool doesMatch(SlowBitvector deductionString, SlowBitvector candidateBitvector, int insertionIndex)
        {
            if (insertionIndex + candidateBitvector.vector.Count <= deductionString.vector.Count)
            {
                return(false);
            }

            int overlapEndIndex = Math.Min(deductionString.vector.Count, insertionIndex + candidateBitvector.vector.Count);
            int overlapLength   = overlapEndIndex - insertionIndex;

            Debug.Assert(overlapLength >= 0, "Overlap length isn't allowed to be negative!");

            // fast exit
            if (overlapLength == 0)
            {
                return(true);
            }

            SlowBitvector cuttedDeductionString    = deductionString.subvector((uint)insertionIndex, (uint)overlapEndIndex);
            SlowBitvector cuttedCandidateBitvector = candidateBitvector.subvector(0, (uint)overlapLength);

            return(checkOverlapEqual(cuttedDeductionString, cuttedCandidateBitvector));
        }
Exemplo n.º 6
0
        public static Prediction predictNextBit(SlowBitvector deductionString, uint order)
        {
            Debug.Assert(order != 0, "Order is not allowed to be zero!");
            if (order == 0)
            {
                throw new SystemException("Order is not allowed to be zero!");
            }

            bool isOrderInfinite = order == -1;


            // TODO< implement for infinite order (== -1) and other orders
            Debug.Assert(order == 1, "Only implemented for order == 1! TODO");

            ulong
                falseCounter = 0,
                trueCounter  = 0;

            // should take continuation without direct evidence into account?
            bool takeFloatingonsiderationIntoAccount = true;
            int  startIndexDeltaFromEnding           = takeFloatingonsiderationIntoAccount ? 0 : -1;

            for (int insertionIndex = deductionString.vector.Count + startIndexDeltaFromEnding; insertionIndex >= 1; insertionIndex--)
            {
                Console.WriteLine("InsertionIndex={0}", insertionIndex);

                for (int startIndex = 0; startIndex < deductionString.vector.Count + 1; startIndex++)
                {
                    for (int endIndex = startIndex + 1; endIndex < deductionString.vector.Count + 1; endIndex++)
                    {
                        SlowBitvector deductionStringSub = deductionString.subvector((uint)startIndex, (uint)endIndex);


                        Console.WriteLine("");

                        Console.WriteLine("{0}", debugBitvector(deductionString));
                        Console.WriteLine("{0}", generateVoidString((uint)insertionIndex) + debugBitvector(deductionStringSub));

                        bool matches = doesMatch(deductionString, deductionStringSub, insertionIndex);
                        Console.WriteLine("does match={0}", matches);

                        // TODO< if does match the extract the candidate bit and increment the counter >
                        if (matches && (insertionIndex + endIndex >= deductionString.vector.Count))
                        {
                            Console.WriteLine("==>HERE");

                            // extract candidate bit
                            int  deductionStringSubIndex = deductionString.vector.Count - insertionIndex;
                            bool candidateSymbol         = deductionStringSub.vector[deductionStringSubIndex];
                            if (candidateSymbol)
                            {
                                trueCounter++;
                            }
                            else
                            {
                                falseCounter++;
                            }
                        }
                    }
                }
            }

            return(new Prediction(trueCounter, falseCounter));
        }
Exemplo n.º 7
0
        /*
         * private static void countPossibleExtensionsOf(SlowBitvector deductionString, SlowBitvector testVector, ref ulong falseCounter, ref ulong trueCounter) {
         *  Console.WriteLine("countPossibleExtensionsOf()");
         *
         *  for (int deltaIn = 0; deltaIn < Math.Min(deductionString.vector.Length, testVector.vector.Length); deltaIn++) {
         *      SlowBitvector beginOverlap = deductionString.subvector((uint)(deductionString.vector.Length - 1 - deltaIn), (uint)(deductionString.vector.Length - 1));
         *
         *      Console.WriteLine("  beginOverlapVector={0}", debugBitvector(beginOverlap));
         *
         *      bool isValidOverlap = checkValidOverlap(beginOverlap, testVector);
         *      if (!isValidOverlap) {
         *          continue;
         *      }
         *
         *      Console.WriteLine("  (is valid overlap)");
         *
         *
         *      // extract bit and count up
         *      // BUGGY; TODO
         *      bool extractedCandidateBit = testVector.vector[deltaIn];
         *
         *      Console.WriteLine("  extractedCandidateBit={0}", extractedCandidateBit);
         *
         *      if   (extractedCandidateBit) { trueCounter++; }
         *      else                         { falseCounter++; }
         *  }
         * }*/

        private static bool checkOverlapEqual(SlowBitvector a, SlowBitvector b)
        {
            Debug.Assert(a.vector.Count == b.vector.Count, "Must have same length!");
            return(a == b);
        }