replace k with sample_index