TangMmmmm / Hidden-Markov-Model

A Java implementation of Hidden Markov Model. The implementation contains Brute Force, Forward-backward, Viterbi and Baum-Welch algorithms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hidden-Markov-Model

A Java implementation of Hidden Markov Model. The implementation contains Brute Force, Forward-backward, Viterbi and Baum-Welch algorithms

Hidden Markov Model is a classifier that is used in different way than the other Machine Learning classifiers. HMM depends on sequences that are shown during sequential time instants. It has many applications such as weather predictions and shines in Speech recognition applications.

After I finish the implementation, I will put the full tutorial of HMM and the javadoc of the API.

Implemented (continuously updating)

  • Json reader
  • Data Validation for an HMM
  • Forward-Backward Algorithm
  • Viterbi Algorithm
  • Baum-Welch Algorithm
  • Javadoc

Json Reader

You can create your model using Json files. In the repository, you will see an example of a model written in a specific expression. I added this feature to help the user to avoid the hard-coding part when entering the model data such as transition and emission matrices.

The Json file is divided to 2 parts, the model info and model data. In model data, you put some information about the model, this enables you when you deal with large amount of models in your projects.

"modelInfo": {
        "name": "HMM1",
		"created_at": "19/12/2015",
		"for": "testing"
	}

You can manually change these data as you wish.

The second part is the model data which is the core of the HMM

"modelData": {
				"states": "R, S, C",
				"initial_prop": "R->0.3, S->0.4, C->0.3",
				"observations": "F, U, D",
				"transition_matrix": "R->R->0.2, R->S->0.1, R->C->0.7, S->R->0.3, S->S->0.4, S->C->0.3, C->R->0.1, C->S->0.4, C->C->0.5",
				"emission_matrix": "R->F->0.4, R->U->0.5, R->D->0.1, S->F->0.4, S->U->0.0, S->D->0.6, C->F->0.4, C->U->0.2, C->D->0.4"
	}

alt tag

How to use

First of all, you should make an instance of the HMM class

HiddenMarkovModel hmm = new HiddenMarkovModel(name, states, observations, initialProbabilities, transitionMatrix, emissionMatrix);

You can create the HMM constructor parameters using 2 ways

  • Put your model data in a json file, then read it like that
JsonParser jp = new JsonParser("G:\\Github Repositories\\Hidden-Markov-Model\\Resources\\test_HMM.json");
String name = DataDecoding.getInstance().getModelName(jp.getName());
Vector<String> states = DataDecoding.getInstance().getStates(jp.getStates());
Vector<String> observations = DataDecoding.getInstance().getObservations(jp.getObservations());
Hashtable<String, Double> initialProbabilities = DataDecoding.getInstance().getInitialProbabilities(jp.getInitialProbabilities());
Hashtable<Pair<String, String>, Double> transitionMatrix = DataDecoding.getInstance().getTransitionMatrix(jp.getTransitionMatrix());
Hashtable<Pair<String, String>, Double> emissionMatrix = DataDecoding.getInstance().getEmissionMatrix(jp.getEmissionMatrix());
  • Hard-code your parameters by setting the elements one by one for each parameter

Tutorials

About

A Java implementation of Hidden Markov Model. The implementation contains Brute Force, Forward-backward, Viterbi and Baum-Welch algorithms

License:MIT License


Languages

Language:Java 99.8%Language:HTML 0.2%