Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adrianulbona/hmm
Hidden Markov Models Java Library
https://github.com/adrianulbona/hmm
Last synced: 10 days ago
JSON representation
Hidden Markov Models Java Library
- Host: GitHub
- URL: https://github.com/adrianulbona/hmm
- Owner: adrianulbona
- License: apache-2.0
- Created: 2016-01-13T03:48:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-12-20T07:57:08.000Z (almost 8 years ago)
- Last Synced: 2024-10-13T00:10:55.441Z (25 days ago)
- Language: Java
- Homepage: http://adrianulbona.github.io/hmm/
- Size: 54.7 KB
- Stars: 40
- Watchers: 8
- Forks: 19
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## HMM abstractions in Java 8
[![Build Status](https://travis-ci.org/adrianulbona/hmm.svg)](https://travis-ci.org/adrianulbona/hmm)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.github.adrianulbona/hmm/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.github.adrianulbona/hmm)Besides the basic abstractions, a most probable state sequence solution is implemented based on the Viterbi algorithm.
### The library is hosted on Maven Central:
#### Maven
```xmlio.github.adrianulbona
hmm
0.1.0```
#### Gradle
```groovy
compile 'io.github.adrianulbona:hmm:0.1.0'
```### How to use it:
#### Getting the most probable sequence of states based on a sequence of observations:
```java
Model model = WikipediaViterbi.INSTANCE.model;
List symptoms = asList(NORMAL, COLD, DIZZY);
List evolution = new MostProbableStateSequenceFinder<>(model).basedOn(symptoms);
```#### How to define a model:
```java
public enum WikipediaViterbi {
INSTANCE;public final Model model;
WikipediaViterbi() {
model = new Model<>(probabilityCalculator(), reachableStatesFinder());
}public enum MedicalState implements State {
HEALTHY,
FEVER;
}
public enum Symptom implements Observation {
NORMAL,
COLD,
DIZZY;
}
private ProbabilityCalculator probabilityCalculator() {
return new ProbabilityCalculator<>(StartProbabilities.INSTANCE.data::get,
EmissionProbabilities.INSTANCE.data::get,
TransitionProbabilities.INSTANCE.data::get);
}private ReachableStateFinder reachableStatesFinder() {
return observation -> asList(MedicalState.values());
}private enum StartProbabilities {
INSTANCE;public final Map data;
StartProbabilities() {
data = new HashMap<>();
data.put(MedicalState.HEALTHY, 0.6);
data.put(MedicalState.FEVER, 0.4);
}
}private enum TransitionProbabilities {
INSTANCE;public final Map, Double> data;
TransitionProbabilities() {
data = new HashMap<>();
data.put(new Transition<>(MedicalState.HEALTHY, MedicalState.HEALTHY), 0.7);
data.put(new Transition<>(MedicalState.HEALTHY, MedicalState.FEVER), 0.3);
data.put(new Transition<>(MedicalState.FEVER, MedicalState.HEALTHY), 0.4);
data.put(new Transition<>(MedicalState.FEVER, MedicalState.FEVER), 0.6);
}
}private enum EmissionProbabilities {
INSTANCE;public final Map, Double> data;
EmissionProbabilities() {
data = new HashMap<>();
data.put(new Emission<>(MedicalState.HEALTHY, Symptom.NORMAL), 0.5);
data.put(new Emission<>(MedicalState.HEALTHY, Symptom.COLD), 0.4);
data.put(new Emission<>(MedicalState.HEALTHY, Symptom.DIZZY), 0.1);
data.put(new Emission<>(MedicalState.FEVER, Symptom.NORMAL), 0.1);
data.put(new Emission<>(MedicalState.FEVER, Symptom.COLD), 0.3);
data.put(new Emission<>(MedicalState.FEVER, Symptom.DIZZY), 0.6);
}
}
}
```