implementation of ffm. For more information, see http://blog.csdn.net/jediael_lu/article/details/77772565