Replace function and weights.