added extract_weighted_sample