How to generate optimal values of the weights