add sample_by_weights function