public static float Run(RandomWalk rw, float epsilonNormalized)
        {
            float          epsilon       = InformationContent.DenormalizeEpsilon(rw, epsilonNormalized);
            ChangeSequence sequence      = new ChangeSequence(rw, epsilon);
            var            probabilities = InformationContent.GetProbabilities(sequence);
            float          entropy       = GetEntropy(probabilities);

            return(entropy);
        }
        public static float Run(RandomWalk rw, float epsilonNormalized)
        {
            float          epsilon  = InformationContent.DenormalizeEpsilon(rw, epsilonNormalized);
            ChangeSequence sequence = new ChangeSequence(rw, epsilon);
            float          mu       = EstimateSlopeNumberIterative(sequence);
            //float mu = EstimateSlopeNumberRecursive(sequence, 0, 0, 0);
            float pic = mu / sequence.Size;

            return(pic);
        }
 private static int EstimateSlopeNumberRecursive(ChangeSequence sequence, int i, int j, int k)
 {
     if (i >= sequence.Size)
     {
         return(k);
     }
     if (j == 0 && sequence.Get(i) != ChangeSymbol.Zero)
     {
         return(EstimateSlopeNumberRecursive(sequence, i + 1, i, k + 1));
     }
     if (j > 0 && sequence.Get(i) != ChangeSymbol.Zero && sequence.Get(i) != sequence.Get(j))
     {
         return(EstimateSlopeNumberRecursive(sequence, i + 1, i, k + 1));
     }
     return(EstimateSlopeNumberRecursive(sequence, i + 1, j, k));
 }
        private static int EstimateSlopeNumberIterative(ChangeSequence sequence)
        {
            int          slopes = 0;
            ChangeSymbol lastSymbol = ChangeSymbol.Zero, currentSymbol;

            for (int i = 0; i < sequence.Size; ++i)
            {
                currentSymbol = sequence.Get(i);
                if ((currentSymbol == ChangeSymbol.One && lastSymbol != ChangeSymbol.One) ||
                    (currentSymbol == ChangeSymbol.BarOne && lastSymbol != ChangeSymbol.BarOne))
                {
                    ++slopes;
                    lastSymbol = currentSymbol;
                }
            }
            return(slopes);
        }
Esempio n. 5
0
        internal static Dictionary <Tuple <ChangeSymbol, ChangeSymbol>, float> GetProbabilities(ChangeSequence sequence)
        {
            var occurrences = new Dictionary <Tuple <ChangeSymbol, ChangeSymbol>, int>();

            foreach (ChangeSymbol symbol1 in Enum.GetValues(typeof(ChangeSymbol)))
            {
                foreach (ChangeSymbol symbol2 in Enum.GetValues(typeof(ChangeSymbol)))
                {
                    occurrences.Add(new Tuple <ChangeSymbol, ChangeSymbol>(symbol1, symbol2), 0);
                }
            }
            for (int i = 0; i < sequence.Size - 1; ++i)
            {
                ChangeSymbol symbol1 = sequence.Get(i);
                ChangeSymbol symbol2 = sequence.Get(i + 1);
                var          key     = occurrences.Keys.Where(k => k.Item1 == symbol1 && k.Item2 == symbol2).Single();
                ++occurrences[key];
            }
            var probabilities = new Dictionary <Tuple <ChangeSymbol, ChangeSymbol>, float>();

            foreach (var pair in occurrences)
            {
                probabilities.Add(pair.Key, (float)pair.Value / (sequence.Size - 1));
            }
            return(probabilities);
        }