Added weighted_model function