add sub sampling function