<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def deviance(self, endog, mu, freq_weights=1., scale=1.):
 r""" Gamma deviance function Parameters endog : array-like Endogenous response variable mu : array-like Fitted mean response variable freq_weights : array-like 1d array of frequency weights. The default is 1. scale : float, optional An optional scale argument. The default is 1. Returns ------- deviance : float Deviance function as defined below """

        endog_mu = self._clean(endog/mu)
        return 2*np.sum(freq_weights*((endog-mu)/mu-np.log(endog_mu)))