Optimize calculating of initial weights.