added matrix ver. for updating weights