CS代考 # The code below implements a HMM state and symbol sequence simulator.

# The code below implements a HMM state and symbol sequence simulator.
# You may want to change the data structures used for emission/transition matrices and the state/symbol sequences/names.
# Changes like this would require small changes to the code.
# also note that the start state s needs to be randomly chosen outside of the simulate_HMM method.

Copyright By PowCoder代写 加微信 powcoder

import numpy as np
import pandas

# Transition matrix a, emission matrix e, number of simulations n, starting state s
def simulate_HMM(a, e, n, s):
symbols = []
states = []
for i in range(n):
symbolEmitted = np.random.choice(list(e.T.index), 1, p = list(e.T[s]))[0]
symbols.append(symbolEmitted)
states.append(s)
s = np.random.choice(list(a.T.columns), 1, p = list(a.T[s]))[0]
return “”.join(symbols), “”.join(states)

stateNames = list(“HST”)
symbolNames = list(“BIN”)

# Will transpose the matrices for easier access to rows (which are now columns)
transitionMatrix = pandas.DataFrame(np.matrix(‘0.33 0.33 0.34; 0.33 0.33 0.34; 0.33 0.33 0.34’), index=stateNames, columns=stateNames)
emissionMatrix = pandas.DataFrame(np.matrix(‘0.33 0.33 0.34; 0.33 0.33 0.34; 0.33 0.33 0.34’), index=stateNames, columns=symbolNames)

程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com