def residual(params, t, y, y_err, inclination, prec_period): alpha = params['alpha'].value delta = params['delta'].value rho1 = params['rho1'].value rho2 = params['rho2'].value T1 = params['T1'].value cos_phi0_1 = width_rl(t, alpha, delta, T1, rho1, inclination, prec_period) # For the second pole, we assume that it is directly opposite to the first pole. # The other parameters delta and T1 are universal to the system cos_phi0_2 = width_rl(t, (np.pi-alpha), delta, T1, rho2, inclination, prec_period) cos_phi0 = np.array([cos_phi0_1, cos_phi0_2]) # print y # print cos_phi0 # print y_err # Divide by data uncertainty, so that minimizer will minimize # sum((y-cos_phi0)**2/y_err**2) # Flatten all arrays (2D) to get 1D arrays before calculating residuals: return np.abs(y.flatten()-cos_phi0.flatten())/y_err.flatten()
def residual(params, t, y, y_err, inclination, prec_period): alpha = params['alpha'].value delta = params['delta'].value rho = params['rho'].value T1 = params['T1'].value cos_phi0 = width_rl(t, alpha, delta, T1, rho, inclination, prec_period) # print y # print cos_phi0 # print y_err # Divide by data uncertainty, so that minimizer will minimize # sum((y-cos_phi0)**2/y_err**2) return np.abs(y-cos_phi0)/y_err
def residual(params, t, y, y_err, n_rho, inclination, prec_period): alpha = params['alpha'].value delta = params['delta'].value rho = [] T1 = params['T1'].value # Will do successive calculations with same parameters, changing only the # value of rho to be fit. cos_phi0 = [] for i_rho in np.arange(n_rho): rho_str = 'rho_'+str(i_rho) rho = params[rho_str].value # rho2 = params['rho2'].value cos_phi0.append(width_rl(t[i_rho], alpha, delta, T1, rho, inclination, prec_period)) cos_phi0 = np.array(cos_phi0) ###cos_phi0_1 = width_rl(t, alpha, delta, T1, rho1, inclination, prec_period) # For the second pole, we assume that it is directly opposite to the first pole. # The other parameters delta and T1 are universal to the system # cos_phi0_2 = width_rl(t, (np.pi-alpha), delta, T1, rho2, inclination, prec_period) # Will do successive calculations with same parameters, changing only the value # of rho to be fit. ###cos_phi0_2 = width_rl(t, (np.pi-alpha), delta, T1, rho2, inclination, prec_period) # cos_phi0 = np.array([cos_phi0_1, cos_phi0_2]) # print y # print cos_phi0 # print y_err # Divide by data uncertainty, so that minimizer will minimize # sum((y-cos_phi0)**2/y_err**2) # Flatten all arrays (2D) to get 1D arrays before calculating residuals: return np.abs(y.flatten()-cos_phi0.flatten())/y_err.flatten()