Calculation of necessary weights