Fix learning algorithm to pass all Java tests.