Package: hmmBaumWelch
hmmBaumWelchImplements the Baum-Welch expectation maximisation algorithm to update the parameters and perform inference on hidden Markov models (HMM) with observed time-series data (for one or multiple variables). In brief, this package maximises the local probabilty of observing the given sequence of variables by updating the HMM initial state, prior, and transition state probabilities. It then performs inference to give the hidden state sequence as well as rendering the probability of a given hidden state at each time point.The package is designed to work with SciPy's probability distribution functions to simplify the defining of the Bayesian priors for each variable and state; and a simple form of "early stopping" has been implemented to optimise performance.InstallationUse the package managerpipto install hmmBaumWelch.pipinstall-ihttps://test.pypi.org/simple/hmmBaumWelchUsagefromhmmBaumWelchimportBaumWelchFor examples of package implementation, see theexamplesdirectory.When instantiating the BaumWelch object, several arguments are expected:N: the number of hidden states within the system. E.g., if N=2, Zi will be in set {0,1}.O_list: a list of list representing each observed, numeric variable. These can be continuous or discreet, but must contain real numbers. They must also be of equal lengths.pi: the starting probabilities (i.e. at t=0) for all hidden states. This is a list of length=N.A: the transition state matrix: a square numpy array, in which each dimension is equal to the number of states N. Each position represents the probability of transitioning between states, i.e., A(0,0) = P(Zi=0,t=t, Zi=0,t=t+1) - the probability that a hidden state will remain in Zi=0 from one time point to the next. Therefore each row of A must sum to one.B_list: a list of prior probability distributions for each variable and all hidden states. These probability distributions can be defined straight from the Scipy package.An example might be:HMM = BaumWelch(N=2, O_list=O_list, pi=[0.5, 0.5], A=np.array([[0.8, 0.2], [0.2, 0.8]]), B_list=B_list)After instantiating the object, expectation maximisation is performed to fit the hidden Markov model. For example:HMM.baumwelch_expectationMaximisation(iter=50, update_pi=True, update_A=True, update_B=False, early_stopping=True)The arguments state that there will be a maximum of 50 iterations of expectation maximisation (stopping early if a good fit found); the starting probabilities, pi, and transition state probability matrix, A, will be updated also, but the priors will remain static. The results can then be extracted with theZ_state_probs_inferencemethod, e.g.:_, _, Z_inference, gamma_meanR = HMM.Z_state_probs_inference()Z_inferenceis an array of integers, stating the inferred hidden states at each time step; and gamma_meanR is the probability of each hidden state at each time step, given the final HMM parameters. If the optionalobservables_weightsparameter was entered at instantiation, each variable will have a concomitant weighting in the parameter updates and final inference.TheoryFor a summary of the Baum-Welch algorithm, see theWikipedia page; and for formal mathematical notation, see the project readme.ContributorsGeorge Stanley.LicenseGNU GENERAL PUBLIC LICENSE Version 2