update w every K iterations