modify calculate_all_penalty_function