Fixed some bug. Add log for debug. Problems: energy = +Inf, weight=nan .