Beispiel #1
0
        return M[state, observation_index]

    def transition_model(self, old_state, new_state):
        """
        Takes in two states to calculate P(new_state | old_state)
        """
        M = np.array([[.5, .2, .1, .2], [.2, .5, .2, .1], [.1, .2, .5, .2],
                      [.2, .1, .2, .5]])
        return M[old_state, new_state]


if __name__ == "__main__":
    """
    Runs A REPL function where you can add observations as letters, and it returns the ask() value of the current
    timepoint. You Can also change the model to the mismatchedObservations model to hand simulate more easily!
    """
    model_instance = suppliedModel()
    #model_instance = mismatchedObservations()
    my_HMM = HMM(
        model_instance.sensor_model,
        model_instance.transition_model,
        model_instance.num_states,
    )
    time = 0
    for i in range(10):
        observation = input("Enter an observation: \n")
        my_HMM.tell(observation)
        time += 1
        print(my_HMM.ask(time))
    print(my_HMM.ask(20))
Beispiel #2
0
        observation_index = self.char_to_int(observation)
        M = np.array([[.5, .2, .3], [.4, .5, .1], [.1, .2, .7], [.1, .9, .0]])
        return M[state, observation_index]

    def transition_model(self, old_state, new_state):
        """
        Takes in two states to calculate P(new_state | old_state)
        """
        M = np.array([[.5, .2, .1, .2], [.2, .5, .2, .1], [.1, .2, .5, .2],
                      [.2, .1, .2, .5]])
        return M[old_state, new_state]


if __name__ == "__main__":
    """
    Runs A REPL function where you can add observations as letters, and it returns the ask() value of the current
    timepoint. You Can also change the model to the mismatchedObservations model to hand simulate more easily!
    """
    model_instance = suppliedModel()
    my_HMM = HMM(
        model_instance.sensor_model,
        model_instance.transition_model,
        model_instance.num_states,
    )
    time = 0
    for i in range(10):
        observation = input("Enter an observation: \n")
        my_HMM.tell(observation)
        time += 1
        print(my_HMM.ask(time))