public Pair<Double, Integer> estimate(WordIndexScanner scanner) {

        int lastWord=0;
        double logp=0;
        int wordCount=0;
        int word;

        flush();

        while ((word = scanner.next()) != -1) {
            // Compute probability
            compute(lastWord, word);
            logp += Math.log10(outputLayer.neurons.get(word, 0));
            wordCount += 1;

            // Copy hidden layer to recurrent layer
            recurrentLayer.neurons = hiddenLayer.neurons.copy();

            // Ending
            lastWord = word;
            for (int i = conf.maxNgramOrder - 1; i > 0; --i) {
                history[i] = history[i - 1];
            }
            history[0]=lastWord;

            if (conf.independent && (word==0)) {
                reset();
            }
        }
        return new Pair<Double, Integer>(logp, wordCount);
    }