private double lambda(int n) {
        if (lambda == null) {
            lambda = new double[(int)order];
            int[] total = new int[(int)order];
            int[] singles = new int[(int)order];
            for (String word : ngrams.keySet()) {
                if (word.length() > 0) {
                    int k = word.length() - 1;
                    int times = ngrams.get(word).getValue();
                    total[k] += times;
                    if (times == 1) {
                        ++singles[k];
                    }
                }
            }
            for (int k = 0; k < order; ++k) {
                lambda[k] = singles[k] / (double) total[k];
            }
        }
        return lambda[n];
    }