Matlab version of RbmStack for comparison.