@Override
    public void expectationMaximization(String fileName) {
        TextReader txreader = new TextReader(fileName, WordType.LETTERS);
        String word;
        Value<State> times = new Value<State>();
        HashMap<State, Value<Character>> restart =
                new HashMap<State, Value<Character>>();
        for (State s : Q) {
            restart.put(s, new Value<Character>());
        }
        try {
            while ((word = txreader.nextWord()) != null) {
                trainWord(word + EOW, times, restart);
            }
            for (State q : Q) {
                if (times.containsKey(q)) {
                    q.setTimes(times.get(q));
                    q.setRestart(restart.get(q));
                } else {
                    q.clean();
                }
            }
        } catch (java.io.IOException x) {
            System.err.println(x);
        }
    }