Update algorithms.py

weight_function() modified.