Latentsvm caskade

reopen PR #3 

WIP
use std::min and std::max instead of macros