fixes to agree with Yue Shi's matlab reference code

* allow optional training set