Пример #1
0
        /// <summary>
        /// Gets the state machine all possible timestamps, with states from state machines corresponing to timestamps on Nokia, Samsung, Motorola, UNIX etc.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_All state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_All state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimeStamp_All(int weight)
        {
            StateMachine timeStampAll = new StateMachine { Name = MachineList.TimeStamp_All, _weight = weight };

            List<StateMachine> machines = new List<StateMachine>()
                                              {
                                                    GetTimestamp_NokiaAll(1),
                                                    GetTimestamp_Samsung(1),
                                                    GetTimestamp_MotoSms(1),
                                                    //GetTimestamp_Sms(1),
                                                    GetTimestamp_SmsGsm(1),
                                                    GetCallLog_MotoTypeAndTime(1),
                                                    GetCallLogTimeStamp_Nokia(1),
                                                    GetTimestamp_Epoch1900Tuple(1)
                                              };

            for (int i = 0; i < machines.Count; i++)
            {
                timeStampAll.StartingStates.AddRange(machines[i].StartingStates);
                timeStampAll.EndingStates.AddRange(machines[i].EndingStates);
                timeStampAll.AddState(machines[i]._states);
            }

            return timeStampAll;
        }
Пример #2
0
        /// <summary>
        /// Gets the meta state machine for an address book entry of a Nokia phone.
        /// </summary>
        /// <param name="weight">Weight of AddressBook_Nokia state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to AddressBook_Nokia state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_AddressBook_Nokia(int weight)
        {
            StateMachine metaAddressBook = new StateMachine { Name = MachineList.Meta_AddressBookNokia, _weight = weight };

            State text = new State { Name = "Text", ParentStateMachine = metaAddressBook };
            State binary1 = new State { Name = "Binary1", ParentStateMachine = metaAddressBook, IsBinary = true };
            State binary2 = new State { Name = "Binary2", ParentStateMachine = metaAddressBook, IsBinary = true };
            State index = new State { Name = "NumberIndex", ParentStateMachine = metaAddressBook };
            State phoneNumber = new State { Name = "PhoneNumber", ParentStateMachine = metaAddressBook };

            metaAddressBook.AddState(text);
            metaAddressBook.AddState(binary1);
            metaAddressBook.AddState(binary2);
            metaAddressBook.AddState(phoneNumber);
            metaAddressBook.AddState(index);

            metaAddressBook.StartingStates.Add(text);
            metaAddressBook.EndingStates.Add(phoneNumber);

            AddTransition(text, binary1, 1d);
            AddTransition(binary1, index, 1d);
            AddTransition(index, binary2, 1d);
            AddTransition(binary2, phoneNumber, 1d);
            AddTransition(phoneNumber, binary1, 0.5d);

            phoneNumber.RemainingProbability = 0.5d;

            text.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1d;

            binary1.PossibleValueProbabilities[(byte)MetaMachine.Binary] = 1d;
            binary2.PossibleValueProbabilities[(byte)MetaMachine.Binary] = 1d;
            index.PossibleValueProbabilities[(byte)MetaMachine.CallLogNumberIndex] = 1d;
            phoneNumber.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1d;

            return metaAddressBook;
        }
Пример #3
0
        /// <summary>
        /// Gets the meta state machine for any possible call log record, with states coming from several state machines corresponding to Motorola Call Log, Nokia Call Log, Samsung Call Log., Generic Call Log.
        /// </summary>
        /// <param name="weight">Weight of CallLogAll state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to CallLogAll state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_CallLogAll(int weight)
        {
            StateMachine timeStampAll = new StateMachine { Name = MachineList.Meta_CallLogAll, _weight = weight };

            List<StateMachine> machines = new List<StateMachine>()
                                              {
                                                    //GetMeta_CallLogNokiaSingle(2),
                                                    GetMeta_CallLogNokiaMulti_v2(2),
                                                    GetMeta_CallLogMoto(2),
                                                    GetMeta_CallLogSamsung(2),
                                                    GetMeta_CallLogGeneric(1)
                                                    ,GetMeta_CallLogGeneric2(1) // BL
                                                    ,GetMeta_CallLogGeneric3(1) // BL
                                                    ,GetMeta_CallLogGeneric4(1) // BL
                                              };

            for (int i = 0; i < machines.Count; i++)
            {
                timeStampAll.StartingStates.AddRange(machines[i].StartingStates);
                timeStampAll.EndingStates.AddRange(machines[i].EndingStates);
                timeStampAll.AddState(machines[i]._states);
            }

            return timeStampAll;
        }
Пример #4
0
        /// <summary>
        /// Gets the meta state machine for an address book entry.
        /// </summary>
        /// <param name="weight">Weight of AddressBook state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to AddressBook state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_AddressBook(int weight)
        {
            StateMachine metaAddressBook = new StateMachine { Name = MachineList.Meta_AddressBook, _weight = weight };

            State text0 = new State { Name = "Text0", ParentStateMachine = metaAddressBook };
            State text = new State { Name = "Text", ParentStateMachine = metaAddressBook };
            State binary = new State { Name = "Binary", ParentStateMachine = metaAddressBook, IsBinary = true };
            State binary0 = new State { Name = "Binary0", ParentStateMachine = metaAddressBook, IsBinary = true };
            State prepend = new State { Name = "Prepend", ParentStateMachine = metaAddressBook };
            State phoneNumber = new State { Name = "PhoneNumber", ParentStateMachine = metaAddressBook };

            metaAddressBook.AddState(text);
            metaAddressBook.AddState(binary);
            metaAddressBook.AddState(binary0);
            metaAddressBook.AddState(phoneNumber);
            metaAddressBook.AddState(text0);
            metaAddressBook.AddState(prepend);

            metaAddressBook.StartingStates.Add(text);
            metaAddressBook.StartingStates.Add(text0);
            metaAddressBook.EndingStates.Add(phoneNumber);

            AddTransition(text0, binary0, 1f);
            AddTransition(binary0, text, 1f); //Allow a separation of binary between the two text fields
            AddTransition(text, binary, 0.5f);
            AddTransition(text, phoneNumber, 0.5f);
            AddTransition(binary, prepend, 0.5f);
            AddTransition(binary, phoneNumber, 0.49f);
            AddTransition(binary, binary, 0.01f);
            AddTransition(prepend, phoneNumber, 1f);
            AddTransition(phoneNumber, binary, 0.5f);

            phoneNumber.RemainingProbability = 0.5f;

            text0.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1f;

            text.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1f;

            binary0.PossibleValueProbabilities[(byte)MachineList.Binary] = 1f;

            text.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1d;

            binary.PossibleValueProbabilities[(byte)MetaMachine.Binary] = 1d;

            prepend.PossibleValueProbabilities[(byte)MetaMachine.SmsPrepend] = 1d;

            phoneNumber.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1d;

            return metaAddressBook;
        }
Пример #5
0
        /// <summary>
        /// Gets the meta state machine for any possible address book record.
        /// </summary>
        /// <param name="weight">Weight of AddressBookAll state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to AddressBookAll state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_AddressBookAll(int weight)
        {
            StateMachine addressBookAll = new StateMachine { Name = MachineList.Meta_AddressBookAll, _weight = weight };

            List<StateMachine> machines = new List<StateMachine>()
                                              {
                                                  GetMeta_AddressBook_Nokia(4),
                                                  GetMeta_AddressBook(2),
                                                  GetMeta_AddressBook1(1)
                                              };

            for (int i = 0; i < machines.Count; i++)
            {
                addressBookAll.StartingStates.AddRange(machines[i].StartingStates);
                addressBookAll.EndingStates.AddRange(machines[i].EndingStates);
                addressBookAll.AddState(machines[i]._states);
            }

            return addressBookAll;
        }
Пример #6
0
        /// <summary>
        /// Adding transitions between all combinations of starting and ending states of two state machines.
        /// </summary>
        /// <param name="fromMachine">The state machine whose ending states participate in the transition.</param>
        /// <param name="toMachine">The state machine whose starting states participate in the transition.</param>
        /// <param name="probability">The probability of having a transition between the two given state machines.</param>
        private static void AddTransitionToStateMachine(StateMachine fromMachine, StateMachine toMachine, double probability)
        {
            double normalizedProb_To = probability / toMachine.StartingStates.Count;

            for (int i = 0; i < fromMachine.EndingStates.Count; i++)
            {
                var endState = fromMachine.EndingStates[i];

                double normalizedProb_From = endState.RemainingProbability * normalizedProb_To;

                for (int j = 0; j < toMachine.StartingStates.Count; j++)
                {
                    var startState = toMachine.StartingStates[j];

                    AddTransition(endState, startState, normalizedProb_From);
                }
            }
        }
Пример #7
0
        public static StateMachine GetCallLog_MotoTypeAndTime(int weight)
        {
            var callLogType = GetCallLogType_Moto(1);
            var timeStamp = GetTimestamp_Unix(1);

            var typeAndTime = new StateMachine { Name = MachineList.CallLogTypeAndTimeStamp_Moto, _weight = weight };

            typeAndTime._states.AddRange(callLogType._states);
            typeAndTime._states.AddRange(timeStamp._states);

            typeAndTime.StartingStates.AddRange(callLogType.StartingStates);
            typeAndTime.EndingStates.AddRange(timeStamp.EndingStates);

            AddTransitionToStateMachine(callLogType, timeStamp, 1d);

            return typeAndTime;
        }
Пример #8
0
        /// <summary>
        /// Gets the state machine for the timestamp of a Samsung phone.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_Samsung state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_Samsung state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_Samsung(int weight)
        {
            StateMachine timestamp = new StateMachine { Name = MachineList.TimeStamp_Samsung, _weight = weight };

            State byte1 = new State { Name = "Byte1", ParentStateMachine = timestamp };
            State byte2 = new State { Name = "Byte2", ParentStateMachine = timestamp };
            State byte3 = new State { Name = "Byte3", ParentStateMachine = timestamp };
            //State byte4 = new State { Name = "Byte4", ParentStateMachine = timestamp };
            SamsungTimeState byte4 = new SamsungTimeState { Name = "Byte4Checker", ParentStateMachine = timestamp };

            timestamp.AddState(byte1);
            timestamp.AddState(byte2);
            timestamp.AddState(byte3);
            timestamp.AddState(byte4);

            timestamp.StartingStates.Add(byte1);
            timestamp.EndingStates.Add(byte4);

            AddTransition(byte1, byte2, 1d);
            AddTransition(byte2, byte3, 1d);
            AddTransition(byte3, byte4, 1d);

            // BL
            // Last 12 bits represent year. Determine possible
            // last bytes (little-endian)
            int nyears = 0;
            for (int i = (TimeConstants.START_YEAR) >> 4; i <= (TimeConstants.END_YEAR) >> 4; i++)
            {
                byte4.PossibleValueProbabilities[i] = 1d;
                nyears++;
            }
            if (nyears > 1) byte4.NormalizeProbabilities();

            // Month (1-12) 4 bits and 4 bits of year.
            for (int yr = TimeConstants.START_YEAR; yr <= TimeConstants.END_YEAR; yr++)
            {
                for (byte mn = 1; mn <= 12; mn++)
                {
                    int x = ((yr & 0xf) << 4) | mn;
                    byte3.PossibleValueProbabilities[x] = 1d;
                }
            }
            byte3.NormalizeProbabilities();

            // BL
            // Minutes (0-59) 6 bits, Hours (0-23) 5 bits, Days (1-31) 5 bits
            for (int i = 0; i < 256; i++)
            {
                // 4 bits for day will not be zero.
                if ((i & 0xf8) == 0) continue;
                // 3 bits used by hours will not all be set.
                if ((i & 0x07) == 0x07) continue;
                byte2.PossibleValueProbabilities[i] = 1d;
            }
            byte2.NormalizeProbabilities();
            for (int i = 0; i < 256; i++)
            {
                // Don't permit minutes greater than 59
                if ((i & 0x3f) >= 60) continue;
                byte1.PossibleValueProbabilities[i] = 1d;
            }
            byte1.NormalizeProbabilities();

            return timestamp;
        }
Пример #9
0
        /// <summary>
        /// Gets the state machine for a timestamp correponding to an SMS.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_Sms state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_Sms state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_Sms(int weight)
        {
            var timestamp = new StateMachine { Name = MachineList.TimeStamp_Sms, _weight = weight };

            State year = new State { Name = "Year", ParentStateMachine = timestamp };
            State month = new State { Name = "Month", ParentStateMachine = timestamp };
            State day = new State { Name = "Day", ParentStateMachine = timestamp };
            State hour = new State { Name = "Hour", ParentStateMachine = timestamp };
            State minute = new State { Name = "Minute", ParentStateMachine = timestamp };
            SmsTimeState second = new SmsTimeState { Name = "Second", ParentStateMachine = timestamp };

            timestamp.AddState(year);
            timestamp.AddState(month);
            timestamp.AddState(day);
            timestamp.AddState(hour);
            timestamp.AddState(minute);
            timestamp.AddState(second);

            timestamp.StartingStates.Add(year);
            timestamp.EndingStates.Add(second);

            AddTransition(year, month, 1d);
            AddTransition(month, day, 1d);
            AddTransition(day, hour, 1d);
            AddTransition(hour, minute, 1d);
            AddTransition(minute, second, 1d);

            int yearWeight = 0;

            //int startYr = Math.Max(2010, TimeConstants.START_YEAR);
            int startYr = TimeConstants.START_YEAR;
            for (int i = (startYr - 2000); i <= (TimeConstants.END_YEAR - 2000); i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                year.PossibleValueProbabilities[byteVal] = 1f + yearWeight;

                yearWeight++;
            }

            year.NormalizeProbabilities();

            for (int i = 1; i <= 12; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                month.PossibleValueProbabilities[byteVal] = 1 / 12d;
            }

            for (int i = 1; i <= 31; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                day.PossibleValueProbabilities[byteVal] = 1 / 31d;
            }

            for (int i = 0; i <= 23; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                hour.PossibleValueProbabilities[byteVal] = 1 / 24d;
            }

            for (int i = 0; i <= 59; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                minute.PossibleValueProbabilities[byteVal] = 1 / 60d;
                second.PossibleValueProbabilities[byteVal] = 1 / 60d;
            }

            return timestamp;
        }
Пример #10
0
        /// <summary>
        /// Gets the state machine for all possible timestamps on a Nokia phone.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_NokiaAll state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_NokiaAll state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_NokiaAll(int weight)
        {
            StateMachine timeStampAll = new StateMachine { Name = MachineList.TimeStamp_All, _weight = weight };

            List<StateMachine> machines = new List<StateMachine>()
                                              {
                                                    GetTimestamp_Nokia(1),
                                                    GetTimestamp_NokiaEndian(1)
                                              };

            for (int i = 0; i < machines.Count; i++)
            {
                timeStampAll.StartingStates.AddRange(machines[i].StartingStates);
                timeStampAll.EndingStates.AddRange(machines[i].EndingStates);
                timeStampAll.AddState(machines[i]._states);
            }

            return timeStampAll;
        }
Пример #11
0
        /// <summary>
        /// Gets the state machine for the timestamp of a Nokia endian.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_NokiaEndian state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_NokiaEndian state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_NokiaEndian(int weight)
        {
            StateMachine timestamp = new StateMachine { Name = MachineList.TimeStamp_NokiaEndian, _weight = weight };

            State year1 = new State { Name = "Year1", ParentStateMachine = timestamp };
            State year2 = new State { Name = "Year2", ParentStateMachine = timestamp };

            State month = new State { Name = "Month", ParentStateMachine = timestamp };
            State day = new State { Name = "Day", ParentStateMachine = timestamp };
            State hour = new State { Name = "Hour", ParentStateMachine = timestamp };
            State min = new State { Name = "Min", ParentStateMachine = timestamp };
            NokiaEndianTimeState sec = new NokiaEndianTimeState { Name = "Sec", ParentStateMachine = timestamp };

            timestamp.AddState(year1);
            timestamp.AddState(year2);
            timestamp.AddState(month);
            timestamp.AddState(day);
            timestamp.AddState(hour);
            timestamp.AddState(min);
            timestamp.AddState(sec);

            timestamp.StartingStates.Add(year1);
            timestamp.EndingStates.Add(sec);

            AddTransition(year1, year2, 1d);
            AddTransition(year2, month, 1d);
            AddTransition(month, day, 1d);
            AddTransition(day, hour, 1d);
            AddTransition(hour, min, 1d);
            AddTransition(min, sec, 1d);

            // BL: Year: most significant byte rolls over in 2048
            // so we should be safe
            year2.PossibleValueProbabilities[0x07] = 1d;
            int start = TimeConstants.START_YEAR & 0xff;
            int end = TimeConstants.END_YEAR & 0xff;
            for (int i = start; i <= end; i++)
            {
                year1.PossibleValueProbabilities[i] = 1d;
            }
            year1.NormalizeProbabilities();

            //Month 01 - 12
            for (byte i = 0x01; i <= 0x0C; i++)
            {
                month.PossibleValueProbabilities[i] = 1 / 12d;
            }

            //Day 01 - 31
            for (byte i = 0x01; i <= 0x1F; i++)
            {
                day.PossibleValueProbabilities[i] = 1 / 31d;
            }

            //Hour 00 - 23
            for (byte i = 0x00; i <= 0x17; i++)
            {
                hour.PossibleValueProbabilities[i] = 1 / 24d;
            }

            //Minutes & Seconds 00-59
            for (byte i = 0x00; i <= 0x3B; i++)
            {
                min.PossibleValueProbabilities[i] = 1 / 60d;
                sec.PossibleValueProbabilities[i] = 1 / 60d;
            }
            return timestamp;
        }
Пример #12
0
        public static StateMachine GetAsciiString_WithLength(int weight)
        {
            var ascii = new StateMachine { Name = MachineList.Text_AsciiStringWithLength, _weight = weight };
            var length = new State { Name = "Length", ParentStateMachine = ascii, AllValuesPossible = true, IsBinary = true };
            var asciiChar = new AsciiLengthState { Name = "AsciiLengthChar", LengthState = length, ParentStateMachine = ascii };

            ascii.AddState(length);
            ascii.AddState(asciiChar);

            ascii.StartingStates.Add(length);
            ascii.EndingStates.Add(asciiChar);

            AddTransition(length, asciiChar, 1f);
            AddTransition(asciiChar, asciiChar, 0.99f);
            asciiChar.RemainingProbability = 0.01f;

            asciiChar.PossibleValueProbabilities[0x61] = 1f;

            return ascii;
        }
Пример #13
0
        /// <summary>
        /// Gets the state machine for a timestamp corresponding to a Motorola SMS.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_MotoSms state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_MotoSms state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_MotoSms(int weight)
        {
            var timestamp = new StateMachine { Name = MachineList.TimeStamp_MotoSms, _weight = weight };

            State year = new State { Name = "Year", ParentStateMachine = timestamp };
            State month = new State { Name = "Month", ParentStateMachine = timestamp };
            State day = new State { Name = "Day", ParentStateMachine = timestamp };
            State hour = new State { Name = "Hour", ParentStateMachine = timestamp };
            State minute = new State { Name = "Minute", ParentStateMachine = timestamp };
            MotoSmsTimeState second = new MotoSmsTimeState { Name = "Second", ParentStateMachine = timestamp };

            timestamp.AddState(year);
            timestamp.AddState(month);
            timestamp.AddState(day);
            timestamp.AddState(hour);
            timestamp.AddState(minute);
            timestamp.AddState(second);

            timestamp.StartingStates.Add(year);
            timestamp.EndingStates.Add(second);

            AddTransition(year, month, 1f);
            AddTransition(month, day, 1f);
            AddTransition(day, hour, 1f);
            AddTransition(hour, minute, 1f);
            AddTransition(minute, second, 1f);

            // Year from 1970

            int yearWeight = 0;
            //int startYr = Math.Max(2010, TimeConstants.START_YEAR);
            int startYr = TimeConstants.START_YEAR;
            for (int i = (startYr - 1970); i <= (TimeConstants.END_YEAR - 1970); i++)
            {
                year.PossibleValueProbabilities[i] = 1f + yearWeight;

                yearWeight++;
            }

            for (byte i = 0x01; i <= 0x0c; i++)
            {
                month.PossibleValueProbabilities[i] = 1f;
            }

            for (byte i = 0x01; i <= 0x1f; i++)
            {
                day.PossibleValueProbabilities[i] = 1f;
            }

            for (byte i = 0x00; i <= 0x17; i++)
            {
                hour.PossibleValueProbabilities[i] = 1f;
            }

            for (byte i = 0x00; i <= 0x39; i++)
            {
                minute.PossibleValueProbabilities[i] = 1f;
                second.PossibleValueProbabilities[i] = 1f;
            }

            year.NormalizeProbabilities();
            month.NormalizeProbabilities();
            day.NormalizeProbabilities();
            hour.NormalizeProbabilities();
            minute.NormalizeProbabilities();
            second.NormalizeProbabilities();

            return timestamp;
        }
Пример #14
0
        /// <summary>
        /// Two unsigned 4-byte little-endian epoch times.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_Epoch1900Tuple state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_Epoch1900Tuple state machine.</param>
        /// <returns></returns>        
        public static StateMachine GetTimestamp_Epoch1900Tuple(int weight)
        {
            var timestamp = new StateMachine { Name = MachineList.TimeStamp_Epoch1900Tuple, _weight = weight };

            State epochTime1 = new State { Name = "Epoch1900Tuple1", ParentStateMachine = timestamp };
            State epochTime2 = new State { Name = "Epoch1900Tuple2", ParentStateMachine = timestamp };
            State epochTime3 = new State { Name = "Epoch1900Tuple3", ParentStateMachine = timestamp };
            State epochTime4 = new State { Name = "Epoch1900Tuple4", ParentStateMachine = timestamp };
            State epochTime5 = new State { Name = "Epoch1900Tuple5", ParentStateMachine = timestamp };
            State epochTime6 = new State { Name = "Epoch1900Tuple6", ParentStateMachine = timestamp };
            State epochTime7 = new State { Name = "Epoch1900Tuple7", ParentStateMachine = timestamp };
            Epoch1900Tuple epochTime8 = new Epoch1900Tuple { Name = "Epoch1900Tuple8", ParentStateMachine = timestamp };
            //State epochTime8 = new State { Name = "Epoch1900Tuple8", ParentStateMachine = timestamp };

            timestamp.AddState(epochTime1);
            timestamp.AddState(epochTime2);
            timestamp.AddState(epochTime3);
            timestamp.AddState(epochTime4);
            timestamp.AddState(epochTime5);
            timestamp.AddState(epochTime6);
            timestamp.AddState(epochTime7);
            timestamp.AddState(epochTime8);

            timestamp.StartingStates.Add(epochTime1);
            timestamp.EndingStates.Add(epochTime8);

            AddTransition(epochTime1, epochTime2, 1d);
            AddTransition(epochTime2, epochTime3, 1d);
            AddTransition(epochTime3, epochTime4, 1d);
            AddTransition(epochTime4, epochTime5, 1d);
            AddTransition(epochTime5, epochTime6, 1d);
            AddTransition(epochTime6, epochTime7, 1d);
            AddTransition(epochTime7, epochTime8, 1d);

            DateTime epochTime = new DateTime(1900, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            //DateTime startTime = new DateTime(Math.Max(TimeConstants.START_YEAR, 2011), 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime startTime = new DateTime(TimeConstants.START_YEAR, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime endTime = new DateTime(TimeConstants.END_YEAR, 12, 31, 23, 59, 59, DateTimeKind.Utc);
            uint startEpoch = (uint)(startTime - epochTime).TotalSeconds;
            uint endEpoch = (uint)(endTime - epochTime).TotalSeconds;
            byte[] startEpochBytes = BitConverter.GetBytes(startEpoch);
            byte[] endEpochBytes = BitConverter.GetBytes(endEpoch);
            // little-endian
            for (byte i = startEpochBytes[3]; i <= endEpochBytes[3]; i++)
            {
                epochTime4.PossibleValueProbabilities[i] = 1d;
                epochTime8.PossibleValueProbabilities[i] = 1d;
            }
            epochTime4.NormalizeProbabilities();
            epochTime8.NormalizeProbabilities();

            if (startEpochBytes[3] == endEpochBytes[3])
            {
                for (byte i = startEpochBytes[2]; i <= endEpochBytes[2]; i++)
                {
                    epochTime3.PossibleValueProbabilities[i] = 1d;
                    epochTime7.PossibleValueProbabilities[i] = 1d;
                }
                epochTime3.NormalizeProbabilities();
                epochTime7.NormalizeProbabilities();
            }
            else
            {
                for (int i = 0; i < 256; i++)
                {
                    epochTime3.PossibleValueProbabilities[i] = 1 / 256d;
                    epochTime7.PossibleValueProbabilities[i] = 1 / 256d;
                }
            }

            for (int i = 0; i < 256; i++)
            {
                epochTime1.PossibleValueProbabilities[i] = 1 / 256d;
                epochTime2.PossibleValueProbabilities[i] = 1 / 256d;
                epochTime5.PossibleValueProbabilities[i] = 1 / 256d;
                epochTime6.PossibleValueProbabilities[i] = 1 / 256d;
            }

            return timestamp;
        }
Пример #15
0
 public static void TestStateMachine(StateMachine machineToTest, ref List<StateMachine> machines, ref List<State> states, ref State startState)
 {
     TestStateMachines(new List<StateMachine> { machineToTest }, ref machines, ref states, ref startState);
 }
Пример #16
0
        /// <summary>
        /// Gets the state machine for a binary byte.
        /// </summary>        
        /// <returns></returns>
        public static StateMachine GetBinary()
        {
            StateMachine binary = new StateMachine { Name = MachineList.Binary };
            State binaryByte = new State { Name = "BinaryByte", ParentStateMachine = binary, AllValuesPossible = true, IsBinary = true };
            binary.AddState(binaryByte);
            binary.StartingStates.Add(binaryByte);
            binary.EndingStates.Add(binaryByte);

            AddTransition(binaryByte, binaryByte, 0.1f);
            binaryByte.RemainingProbability = 0.9f;

            return binary;
        }
Пример #17
0
        /// <summary>
        /// Not really used anymore. The CallLog state machines have been shifted into the
        /// meta state machines.
        /// </summary>
        /// <param name="weight"></param>
        /// <returns></returns>
        public static StateMachine GetCallLogType_Moto(int weight)
        {
            var status = new StateMachine { Name = MachineList.CallLogType_Moto, _weight = 1 };

            State type1 = new State { Name = "type1", ParentStateMachine = status };
            State type2 = new State { Name = "type2", ParentStateMachine = status };

            status.AddState(type1);
            status.AddState(type2); ;

            status.StartingStates.Add(type1);
            status.EndingStates.Add(type2);

            AddTransition(type1, type2, 1d);

            type1.PossibleValueProbabilities[0x00] = 1d;

            for (byte i = 0x00; i <= 0x05; i++)
            {
                type2.PossibleValueProbabilities[i] = 1 / 6d;
            }

            var prepend = new StateMachine { Name = MachineList.CallLogTypePrepend_Moto, _weight = 1 };

            State ff1 = new State { Name = "FF1", ParentStateMachine = prepend };
            State ff2 = new State { Name = "FF2", ParentStateMachine = prepend };
            State ff3 = new State { Name = "FF3", ParentStateMachine = prepend };
            State ff4 = new State { Name = "FF4", ParentStateMachine = prepend };

            prepend.AddState(ff1);
            prepend.AddState(ff2);
            prepend.AddState(ff3);
            prepend.AddState(ff4);

            prepend.StartingStates.Add(ff1);
            prepend.EndingStates.Add(ff4);

            AddTransition(ff1, ff2, 1d);
            AddTransition(ff2, ff3, 1d);
            AddTransition(ff3, ff4, 1d);

            ff1.PossibleValueProbabilities[0xff] = 1d;
            ff2.PossibleValueProbabilities[0xff] = 1d;
            ff3.PossibleValueProbabilities[0xff] = 1d;
            ff4.PossibleValueProbabilities[0xff] = 1d;

            var statusWithPrepend = new StateMachine { Name = MachineList.CallLogTypeWithPrepend_Moto, _weight = weight };

            statusWithPrepend.StartingStates.AddRange(prepend.StartingStates);
            statusWithPrepend.EndingStates.AddRange(status.EndingStates);
            statusWithPrepend.AddState(status._states);
            statusWithPrepend.AddState(prepend._states);

            AddTransitionToStateMachine(prepend, status, 1d);

            return statusWithPrepend;
        }
Пример #18
0
        /// <summary>
        /// Gets the state machine for a timestamp correponding to an SMS.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_Sms state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_Sms state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_SmsGsm(int weight)
        {
            var timestamp = new StateMachine { Name = MachineList.TimeStamp_SmsGsm, _weight = weight };

            State year = new State { Name = "Year", ParentStateMachine = timestamp };
            State month = new State { Name = "Month", ParentStateMachine = timestamp };
            State day = new State { Name = "Day", ParentStateMachine = timestamp };
            State hour = new State { Name = "Hour", ParentStateMachine = timestamp };
            State minute = new State { Name = "Minute", ParentStateMachine = timestamp };
            State second = new State { Name = "Second", ParentStateMachine = timestamp };
            SmsGsmTimeState timezone = new SmsGsmTimeState { Name = "Timezone", ParentStateMachine = timestamp };

            timestamp.AddState(year);
            timestamp.AddState(month);
            timestamp.AddState(day);
            timestamp.AddState(hour);
            timestamp.AddState(minute);
            timestamp.AddState(second);
            timestamp.AddState(timezone);

            timestamp.StartingStates.Add(year);
            timestamp.EndingStates.Add(timezone);

            AddTransition(year, month, 1d);
            AddTransition(month, day, 1d);
            AddTransition(day, hour, 1d);
            AddTransition(hour, minute, 1d);
            AddTransition(minute, second, 1d);
            AddTransition(second, timezone, 1d);

            int yearWeight = 0;

            //int startYr = Math.Max(2010, TimeConstants.START_YEAR);
            int startYr = TimeConstants.START_YEAR;
            for (int i = (startYr - 2000); i <= (TimeConstants.END_YEAR - 2000); i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                year.PossibleValueProbabilities[byteVal] = 1f + yearWeight;

                yearWeight++;
            }

            year.NormalizeProbabilities();

            for (int i = 1; i <= 12; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                month.PossibleValueProbabilities[byteVal] = 1 / 12d;
            }

            for (int i = 1; i <= 31; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                day.PossibleValueProbabilities[byteVal] = 1 / 31d;
            }

            for (int i = 0; i <= 23; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                hour.PossibleValueProbabilities[byteVal] = 1 / 24d;
            }

            for (int i = 0; i <= 59; i++)
            {
                var byteTest = byte.Parse(Convert.ToString(i), NumberStyles.HexNumber);
                var byteVal = Printer.SwapNibbles(byteTest);

                minute.PossibleValueProbabilities[byteVal] = 1 / 60d;
                second.PossibleValueProbabilities[byteVal] = 1 / 60d;
            }

            // Each interval represents a 15 minute GMT offset. If the most
            // significant bit (before swapping) is set, it's a negative value.
            for (int i = 0; i < 96; i++)
            {
                // Skip 15 minutes time zones, except Nepal's.
                if (((i % 2) == 1) && (i != 23)) continue;
                // Swapped BCD.
                byte byteVal = Printer.SwapNibbles(Printer.ByteFromNibbles(i / 10, i % 10));
                timezone.PossibleValueProbabilities[byteVal] = 1d;
                if ((i != 0) && (i != 23))
                {
                    // Mark negative (bytes are already swapped)
                    byteVal |= 0x08;
                    timezone.PossibleValueProbabilities[byteVal] = 1d;
                }
            }
            timezone.NormalizeProbabilities();

            return timestamp;
        }
Пример #19
0
        /// <summary>
        /// Call log type 0-2, inclusive as a little-endian integer.
        /// </summary>
        /// <param name="weight">Weight of CallLogType_SimpleLE state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to CallLogType_SimpleLE state machine.</param>
        /// <returns></returns>
        public static StateMachine GetCallLogType_SimpleLE(int weight)
        {
            var status = new StateMachine { Name = MachineList.CallLogType_SimpleLE, _weight = 1 };

            State type1 = new State { Name = "type1", ParentStateMachine = status };
            State type2 = new State { Name = "type2", ParentStateMachine = status };
            State type3 = new State { Name = "type3", ParentStateMachine = status };
            State type4 = new State { Name = "type4", ParentStateMachine = status };

            status.AddState(type1);
            status.AddState(type2);
            status.AddState(type3);
            status.AddState(type4);

            status.StartingStates.Add(type1);
            status.EndingStates.Add(type4);

            AddTransition(type1, type2, 1d);
            AddTransition(type2, type3, 1d);
            AddTransition(type3, type4, 1d);

            for (byte i = 0x00; i <= 0x02; i++)
            {
                type1.PossibleValueProbabilities[i] = 1 / 3d;
            }
            type2.PossibleValueProbabilities[0x00] = 1d;
            type3.PossibleValueProbabilities[0x00] = 1d;
            type4.PossibleValueProbabilities[0x00] = 1d;

            return status;
        }
Пример #20
0
        public static StateMachine GetBinaryFF()
        {
            StateMachine binaryFF = new StateMachine { Name = MachineList.BinaryFF };
            State ffByte1 = new State { Name = "BinaryFF_1", ParentStateMachine = binaryFF, IsBinary = true };
            State ffByte2 = new State { Name = "BinaryFF_2", ParentStateMachine = binaryFF, IsBinary = true };
            State ffByte3 = new State { Name = "BinaryFF_3", ParentStateMachine = binaryFF, IsBinary = true };
            State ffByte4 = new State { Name = "BinaryFF_4", ParentStateMachine = binaryFF, IsBinary = true };
            State ffByte5 = new State { Name = "BinaryFF_5", ParentStateMachine = binaryFF, IsBinary = true };

            binaryFF.AddState(ffByte1);
            binaryFF.AddState(ffByte2);
            binaryFF.AddState(ffByte3);
            binaryFF.AddState(ffByte4);
            binaryFF.AddState(ffByte5);

            ffByte1.PossibleValueProbabilities[0xff] = 1d;
            ffByte2.PossibleValueProbabilities[0xff] = 1d;
            ffByte3.PossibleValueProbabilities[0xff] = 1d;
            ffByte4.PossibleValueProbabilities[0xff] = 1d;
            ffByte5.PossibleValueProbabilities[0xff] = 1d;

            AddTransition(ffByte1, ffByte2, 1d);
            AddTransition(ffByte2, ffByte3, 1d);
            AddTransition(ffByte3, ffByte4, 1d);
            AddTransition(ffByte4, ffByte5, 0.99d);
            ffByte4.RemainingProbability = 0.01d;
            AddTransition(ffByte5, ffByte4, 0.99d);
            ffByte5.RemainingProbability = 0.01d;

            binaryFF.StartingStates.Add(ffByte1);
            binaryFF.EndingStates.Add(ffByte4);
            binaryFF.EndingStates.Add(ffByte5);

            return binaryFF;
        }
Пример #21
0
        public static StateMachine GetCallLog_NokiaNumberIndexAndNumber(int weight)
        {
            var numberIndexAndNumber = new StateMachine { Name = MachineList.CallLogNumberIndexAndNumber_Nokia, _weight = weight };
            var machine = new StateMachine { Name = MachineList.Binary, _weight = 1 };

            State binary1 = new State { Name = "Binary1", ParentStateMachine = machine, AllValuesPossible = true, IsBinary = true };
            State binary2 = new State { Name = "Binary2", ParentStateMachine = machine, AllValuesPossible = true, IsBinary = true };
            State binary3 = new State { Name = "Binary3", ParentStateMachine = machine, AllValuesPossible = true, IsBinary = true };
            State binary4 = new State { Name = "Binary4", ParentStateMachine = machine, AllValuesPossible = true, IsBinary = true };

            machine.AddState(binary1);
            machine.AddState(binary2);
            machine.AddState(binary3);
            machine.AddState(binary4);

            //Set the transition probability to be lower so that this machine does not dominate others. e.g. the international format
            AddTransition(binary1, binary2, 0.1f);
            AddTransition(binary2, binary3, 0.1f);
            AddTransition(binary3, binary4, 0.1f);

            machine.StartingStates.Add(binary1);
            machine.EndingStates.Add(binary4);

            var index = GetPhoneNumber_NokiaNumberIndex(1);
            var number = GetPhoneNumber_NokiaAll(1);

            AddTransitionToStateMachine(index, machine, 1d);
            AddTransitionToStateMachine(machine, number, 1d);

            numberIndexAndNumber.AddState(index._states);
            numberIndexAndNumber.AddState(machine._states);
            numberIndexAndNumber.AddState(number._states);

            numberIndexAndNumber.StartingStates.AddRange(index.StartingStates);
            numberIndexAndNumber.EndingStates.AddRange(number.EndingStates);

            return numberIndexAndNumber;
        }
Пример #22
0
        /// <summary>
        /// Gets the state machine for a UNIX timestamp.
        /// </summary>
        /// <param name="weight">Weight of TimeStamp_Unix state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to TimeStamp_Unix state machine.</param>
        /// <returns></returns>
        public static StateMachine GetTimestamp_Unix(int weight)
        {
            var timestamp = new StateMachine { Name = MachineList.TimeStamp_Unix, _weight = weight };

            State unixTime1 = new State { Name = "UnixTime1", ParentStateMachine = timestamp };
            State unixTime2 = new State { Name = "UnixTime2", ParentStateMachine = timestamp };
            State unixTime3 = new State { Name = "UnixTime3", ParentStateMachine = timestamp };
            UnixTimeState unixTime4 = new UnixTimeState { Name = "UnixTime4", ParentStateMachine = timestamp };

            timestamp.AddState(unixTime1);
            timestamp.AddState(unixTime2);
            timestamp.AddState(unixTime3);
            timestamp.AddState(unixTime4); ;

            timestamp.StartingStates.Add(unixTime1);
            timestamp.EndingStates.Add(unixTime4);

            AddTransition(unixTime1, unixTime2, 1d);
            AddTransition(unixTime2, unixTime3, 1d);
            AddTransition(unixTime3, unixTime4, 1d);

            // BL
            DateTime epochTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            //DateTime startTime = new DateTime(Math.Max(TimeConstants.START_YEAR, 2011), 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime startTime = new DateTime(TimeConstants.START_YEAR, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime endTime = new DateTime(TimeConstants.END_YEAR, 12, 31, 23, 59, 59, DateTimeKind.Utc);
            uint startEpoch = (uint)(startTime - epochTime).TotalSeconds;
            uint endEpoch = (uint)(endTime - epochTime).TotalSeconds;
            byte[] startEpochBytes = BitConverter.GetBytes(startEpoch);
            byte[] endEpochBytes = BitConverter.GetBytes(endEpoch);
            // big-endian
            for (byte i = startEpochBytes[3]; i <= endEpochBytes[3]; i++)
            {
                unixTime1.PossibleValueProbabilities[i] = 1d;
            }
            unixTime1.NormalizeProbabilities();

            for (int i = 0; i < 256; i++)
            {
                unixTime2.PossibleValueProbabilities[i] = 1 / 256d;
                unixTime3.PossibleValueProbabilities[i] = 1 / 256d;
                unixTime4.PossibleValueProbabilities[i] = 1 / 256d;
            }
            return timestamp;
        }
Пример #23
0
        /// <summary>
        /// Gets the meta state machine for an address book entry.
        /// </summary>
        /// <param name="weight">Weight of AddressBook state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to AddressBook state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_AddressBook1(int weight)
        {
            StateMachine metaAddressBook = new StateMachine { Name = MachineList.Meta_AddressBook, _weight = weight };

            State text = new State { Name = "Text", ParentStateMachine = metaAddressBook };
            State binary = new State { Name = "Binary", ParentStateMachine = metaAddressBook, IsBinary = true };
            State phoneNumber = new State { Name = "PhoneNumber", ParentStateMachine = metaAddressBook };

            metaAddressBook.AddState(text);
            metaAddressBook.AddState(binary);

            metaAddressBook.AddState(phoneNumber);

            metaAddressBook.StartingStates.Add(phoneNumber);
            metaAddressBook.EndingStates.Add(text);

            AddTransition(phoneNumber, binary, 0.5f);
            AddTransition(phoneNumber, text, 0.5f);
            AddTransition(binary, text, 1.0f);

            text.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1f;

            binary.PossibleValueProbabilities[(byte)MetaMachine.Binary] = 1d;

            phoneNumber.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1d;

            return metaAddressBook;
        }
Пример #24
0
 /// <summary>
 /// Gets the state machine for a user-defined timestamp.
 /// </summary>
 /// <param name="userState">Object representing the user-defined state machine.</param>
 /// <param name="weight"></param>
 /// <returns>The state machine.</returns>
 public static StateMachine GetTimestamp_UserDefined(UserState userState, int weight)
 {
     StateMachine timestamp = new StateMachine { Name = userState.MachineType, _weight = weight };
     State prevState = null;
     // Have a minimum of 2 bytes.
     for (int n = 0; n < userState.Bytes.Count - 1; n++)
     {
         string nm = String.Format("UserTimestampByte{0}", n);
         State state = new State { Name = nm, ParentStateMachine = timestamp };
         timestamp.AddState(state);
         if (n == 0)
         {
             timestamp.StartingStates.Add(state);
         }
         else
         {
             AddTransition(prevState, state, 1d);
         }
         prevState = state;
         UserDefinedByteProbabilities(state, userState.Bytes[n]);
     }
     UserDefinedTimestampState endState = new UserDefinedTimestampState(userState) { Name = "EndUserTimestampByte", ParentStateMachine = timestamp };
     timestamp.AddState(endState);
     UserDefinedByteProbabilities(endState, userState.Bytes[userState.Bytes.Count - 1]);
     AddTransition(prevState, endState, 1d);
     timestamp.EndingStates.Add(endState);
     return timestamp;
 }
Пример #25
0
        /// <summary>
        /// Gets the meta state machine for a multiple address book entries.
        /// </summary>
        /// <param name="weight">Weight of AddressBook_Multi state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to AddressBook_Multi state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_AddressBook_Multi(int weight)
        {
            StateMachine addressBookMulti = new StateMachine { Name = MachineList.Meta_AddressBookMulti, _weight = weight };
            StateMachine binary = GetMeta_Binary(1);
            StateMachine addressBookAll1 = GetMeta_AddressBookAll(1);
            StateMachine addressBookAll2 = GetMeta_AddressBookAll(1);

            addressBookMulti.StartingStates.AddRange(addressBookAll1.StartingStates);
            addressBookMulti.EndingStates.AddRange(addressBookAll2.EndingStates);

            AddTransitionToStateMachine(addressBookAll1, binary, 1d);
            AddTransitionToStateMachine(binary, addressBookAll2, 1d);

            addressBookMulti.AddState(binary._states);
            addressBookMulti.AddState(addressBookAll1._states);
            addressBookMulti.AddState(addressBookAll2._states);

            return addressBookMulti;
        }
Пример #26
0
        /// <summary>
        /// Gets the state machine corresponing to the Endian of a Unicode string.
        /// </summary>
        /// <returns></returns>
        public static StateMachine GetUnicodeStringEndian()
        {
            StateMachine unicodeString = new StateMachine { Name = MachineList.Text_UnicodeEndian };

            State uniNull0 = new State { Name = "UniNull0", ParentStateMachine = unicodeString };
            State uniChar0 = new State { Name = "UniChar0", ParentStateMachine = unicodeString };

            State uniNull1 = new State { Name = "UniNull1", ParentStateMachine = unicodeString };
            State uniChar1 = new State { Name = "UniChar1", ParentStateMachine = unicodeString };

            State uniNull2 = new State { Name = "UniNull2", ParentStateMachine = unicodeString };
            State uniChar2 = new State { Name = "UniChar2", ParentStateMachine = unicodeString };
            State uniChar2Punct = new State { Name = "UniChar2Punct", ParentStateMachine = unicodeString };

            unicodeString.AddState(uniNull0);
            unicodeString.AddState(uniChar0);
            unicodeString.AddState(uniNull1);
            unicodeString.AddState(uniChar1);
            unicodeString.AddState(uniNull2);
            unicodeString.AddState(uniChar2);
            unicodeString.AddState(uniChar2Punct);

            unicodeString.StartingStates.Add(uniChar0);
            unicodeString.EndingStates.Add(uniNull2);
            unicodeString.EndingStates.Add(uniNull1);

            AddTransition(uniChar0, uniNull0, 1f);
            AddTransition(uniNull0, uniChar1, 1f);
            AddTransition(uniChar1, uniNull1, 1f);
            AddTransition(uniNull1, uniChar2, 0.69f);
            AddTransition(uniNull1, uniChar2Punct, 0.30f);
            uniNull1.RemainingProbability = 0.1f;

            AddTransition(uniChar2, uniNull2, 1f);
            AddTransition(uniChar2Punct, uniNull2, 1f);

            AddTransition(uniNull2, uniChar2, 0.69f);
            AddTransition(uniNull2, uniChar2Punct, 0.30f);
            uniNull2.RemainingProbability = 0.01f;

            uniNull0.PossibleValueProbabilities[0x00] = 1d;
            uniNull1.PossibleValueProbabilities[0x00] = 1d;
            uniNull2.PossibleValueProbabilities[0x00] = 1d;

            uniChar1.PossibleValueProbabilities[0x20] = 1 / 54d;
            uniChar1.PossibleValueProbabilities[0x2D] = 1 / 54d;

            uniChar2.PossibleValueProbabilities[0x20] = 1 / 54d;
            uniChar2.PossibleValueProbabilities[0x2D] = 1 / 54d;

            //Upper case letters
            for (byte i = 0x41; i <= 0x5a; i++)
            {
                uniChar0.PossibleValueProbabilities[i] = 2d;
                uniChar1.PossibleValueProbabilities[i] = 1 / 54d;
                uniChar2.PossibleValueProbabilities[i] = 1 / 54d;
            }

            //Lower case letters
            for (byte i = 0x61; i <= 0x7a; i++)
            {
                uniChar0.PossibleValueProbabilities[i] = 1d;
                uniChar1.PossibleValueProbabilities[i] = 1 / 54d;
                uniChar2.PossibleValueProbabilities[i] = 1 / 54d;
            }

            //printable (non-alpha)
            for (int i = 33; i <= 64; i++)
            {
                uniChar2Punct.PossibleValueProbabilities[i] = 1d;
            }

            uniChar2Punct.PossibleValueProbabilities[0x20] = 1d;

            //printable (non-alpha)
            for (int i = 91; i <= 96; i++)
            {
                uniChar2Punct.PossibleValueProbabilities[i] = 1d;
            }

            //printable (non-alpha)
            for (int i = 123; i <= 127; i++)
            {
                uniChar2Punct.PossibleValueProbabilities[i] = 1d;
            }

            uniChar2Punct.NormalizeProbabilities();
            uniChar0.NormalizeProbabilities();

            return unicodeString;
        }
Пример #27
0
        /// <summary>
        /// Gets the meta state machine for a binary byte.
        /// </summary>
        /// <param name="weight">Weight of Binary state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to Binary state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_Binary(int weight)
        {
            StateMachine binary = new StateMachine { Name = MachineList.Meta_Binary, _weight = weight };

            State binaryByte = new State { Name = "BinaryByte", ParentStateMachine = binary, AllValuesPossible = true, IsBinary = true };

            binary.AddState(binaryByte);
            binary.StartingStates.Add(binaryByte);
            binary.EndingStates.Add(binaryByte);

            return binary;
        }
Пример #28
0
        /// <summary>
        /// Gets the state machine for the timestamp in a call log record on a Nokia phone.
        /// </summary>
        /// <param name="weight">Weight of CallLogTimeStamp_Nokia state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to CallLogTimeStamp_Nokia state machine.</param>
        /// <returns></returns>
        public static StateMachine GetCallLogTimeStamp_Nokia(int weight)
        {
            var timeStamp = GetTimestamp_NokiaAll(1);
            var index = GetPhoneNumber_NokiaNumberIndex(1);

            var timeStampAndIndex = new StateMachine { Name = MachineList.CallLogTimeStamp_Nokia, _weight = weight };

            timeStampAndIndex.AddState(timeStamp._states);
            timeStampAndIndex.AddState(index._states);

            timeStampAndIndex.StartingStates.AddRange(timeStamp.StartingStates);
            timeStampAndIndex.EndingStates.AddRange(index.EndingStates);

            AddTransitionToStateMachine(timeStamp, index, 1d);

            return timeStampAndIndex;
        }
Пример #29
0
        /// <summary>
        /// Gets the meta state machine for a generic Call Log.
        /// </summary>
        /// <param name="weight">Weight of CallLogGeneric state machine, among the set of state machines to be aggregated, governing a prior probability that the inferred sequence of states corresponds to CallLogGeneric state machine.</param>
        /// <returns></returns>
        public static StateMachine GetMeta_CallLogGeneric(int weight)
        {
            StateMachine metaCallLog = new StateMachine { Name = MachineList.Meta_CallLogGeneric, _weight = weight };

            State textStart = new State { Name = "Text", ParentStateMachine = metaCallLog };
            State text = new State { Name = "Text", ParentStateMachine = metaCallLog };
            State binaryA = new State { Name = "Binary", ParentStateMachine = metaCallLog, IsBinary = true };
            State binaryB = new State { Name = "Binary", ParentStateMachine = metaCallLog, IsBinary = true };
            State phoneNumber = new State { Name = "PhoneNumber", ParentStateMachine = metaCallLog };
            State phoneNumberStartWText = new State { Name = "PhoneNumber", ParentStateMachine = metaCallLog };
            State phoneNumberStart = new State { Name = "PhoneNumber", ParentStateMachine = metaCallLog };
            State binary2 = new State { Name = "Binary2", ParentStateMachine = metaCallLog, IsBinary = true };
            State timeStamp = new State { Name = "TimeStamp", ParentStateMachine = metaCallLog };

            metaCallLog.AddState(text);
            metaCallLog.AddState(binaryA);
            metaCallLog.AddState(binaryB);
            metaCallLog.AddState(phoneNumber);
            metaCallLog.AddState(binary2);
            metaCallLog.AddState(timeStamp);
            metaCallLog.AddState(textStart);
            metaCallLog.AddState(phoneNumberStartWText);
            metaCallLog.AddState(phoneNumberStart);

            metaCallLog.StartingStates.Add(textStart);
            metaCallLog.StartingStates.Add(phoneNumberStart);
            metaCallLog.StartingStates.Add(phoneNumberStartWText);
            metaCallLog.EndingStates.Add(timeStamp);

            //Starting path txt -> number
            AddTransition(textStart, binaryA, 1f);
            AddTransition(binaryA, phoneNumber, 0.99f);
            AddTransition(binaryA, binaryA, 0.01f);
            AddTransition(phoneNumber, binary2, 1f);

            //starting path number -> txt
            AddTransition(phoneNumberStartWText, binaryB, 1f);
            AddTransition(binaryB, text, 0.99f);
            AddTransition(binaryB, binaryB, 0.01f);
            AddTransition(text, binary2, 1f);

            //starting path number -> no text
            AddTransition(phoneNumberStart, binary2, 1f);

            AddTransition(binary2, timeStamp, 0.99f);
            AddTransition(binary2, binary2, 0.01f);
            AddTransition(timeStamp, binary2, 0.9f);
            timeStamp.RemainingProbability = 0.1f;

            for (int i = 0; i < 256; i++)
            {
                binaryA.PossibleValueProbabilities[i] = 1f;
                binaryB.PossibleValueProbabilities[i] = 1f;
                binary2.PossibleValueProbabilities[i] = 1f;
            }

            binaryA.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 0f;
            binaryA.PossibleValueProbabilities[(byte)MetaMachine.Text] = 0f;
            binaryA.PossibleValueProbabilities[(byte)MetaMachine.TimeStamp] = 0f;
            binaryA.PossibleValueProbabilities[(byte)MetaMachine.BinaryLarge] = 0f;

            binaryB.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 0f;
            binaryB.PossibleValueProbabilities[(byte)MetaMachine.Text] = 0f;
            binaryB.PossibleValueProbabilities[(byte)MetaMachine.TimeStamp] = 0f;
            binaryB.PossibleValueProbabilities[(byte)MetaMachine.BinaryLarge] = 0f;

            binary2.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 0f;
            binary2.PossibleValueProbabilities[(byte)MetaMachine.Text] = 0f;
            binary2.PossibleValueProbabilities[(byte)MetaMachine.TimeStamp] = 0f;
            binary2.PossibleValueProbabilities[(byte)MetaMachine.BinaryLarge] = 0f;

            binaryA.NormalizeProbabilities();
            binaryB.NormalizeProbabilities();
            binary2.NormalizeProbabilities();

            text.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1f;
            textStart.PossibleValueProbabilities[(byte)MetaMachine.Text] = 1f;
            phoneNumber.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1f;
            phoneNumberStart.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1f;
            phoneNumberStartWText.PossibleValueProbabilities[(byte)MetaMachine.PhoneNumber] = 1f;
            timeStamp.PossibleValueProbabilities[(byte)MetaMachine.TimeStamp] = 1f;

            return metaCallLog;
        }
Пример #30
0
        /// <summary>
        /// Gets the state machine for ASCII string bigrams.
        /// </summary>
        /// <returns></returns>
        public static StateMachine GetAsciiString_Bigram_v1()
        {
            StateMachine asciiString = new StateMachine { Name = MachineList.Text_AsciiBigram };
            BigramState asciiPart1 = new BigramState { Name = "AsciiPart1", ParentStateMachine = asciiString };
            BigramState asciiPart2 = new BigramState { Name = "AsciiPart2", ParentStateMachine = asciiString };
            BigramState asciiPart3 = new BigramState { Name = "AsciiPart3", ParentStateMachine = asciiString };

            asciiString.AddState(asciiPart1);
            asciiString.AddState(asciiPart2);
            asciiString.AddState(asciiPart3);

            asciiString.StartingStates.Add(asciiPart1);
            asciiString.EndingStates.Add(asciiPart3);

            AddTransition(asciiPart1, asciiPart2, 0.1d);
            AddTransition(asciiPart1, asciiPart1, 0.9d);
            AddTransition(asciiPart2, asciiPart3, 0.1d);
            AddTransition(asciiPart2, asciiPart2, 0.9d);

            return asciiString;
        }