def _get_fit(self, errors=None): '''convenience''' errors = errors or [dict(axis='y', err_val=1.0)] _fit = XYFit(xy_data=self._ref_xy_data, model_function=simple_xy_model, cost_function=XYCostFunction_Chi2( axes_to_use='xy', errors_to_use='covariance'), minimizer=self.MINIMIZER) for _err in errors: _fit.add_error(**_err) return _fit
def _get_fit(self, model_function=None, cost_function=None, error=None): '''convenience''' model_function = model_function or simple_xy_model # TODO: fix default cost_function = cost_function or XYCostFunction_Chi2( axes_to_use='xy', errors_to_use='covariance') error = error or 1.0 _fit = XYFit(xy_data=self._ref_xy_data, model_function=model_function, cost_function=cost_function, minimizer=self.MINIMIZER) _fit.add_error(axis='y', err_val=error) return _fit
def _get_fit(self, errors=None): '''convenience''' _fit = XYFit(xy_data=self._ref_xy_data, model_function=simple_xy_model, cost_function=XYCostFunction_Chi2( axes_to_use='xy', errors_to_use='covariance'), minimizer=self.MINIMIZER) if errors is None: _fit.add_matrix_error(axis='y', err_matrix=np.eye(self._n_points), matrix_type='cov') else: for _err in errors: if 'err_matrix' in _err: _fit.add_matrix_error(**_err) else: _fit.add_error(**_err) return _fit
def _get_fit(self, model_function=None, cost_function=None, errors=None, dynamic_error_algorithm=None): '''convenience''' model_function = model_function or simple_xy_model # TODO: fix default cost_function = cost_function or XYCostFunction_Chi2( axes_to_use='xy', errors_to_use='covariance') errors = errors or [dict(axis='y', err_val=1.0)] dynamic_error_algorithm = dynamic_error_algorithm or "nonlinear" _fit = XYFit(xy_data=self._ref_xy_data, model_function=model_function, cost_function=cost_function, minimizer=self.MINIMIZER, dynamic_error_algorithm=dynamic_error_algorithm) for _err in errors: _fit.add_error(**_err) return _fit
def setUp(self): self._n_points = 16 self._default_cost_function = XYCostFunction_Chi2( axes_to_use='xy', errors_to_use='covariance') # "jitter" for data smearing self._y_jitter = np.array([ 0.2991, 1.558, -0.714, 0.825, -1.157, 0.462, 0.103, 1.167, 0.783, -0.688, -1.019, 0.14, -0.11, -0.87, 1.81, 0.35 ]) assert len(self._y_jitter) == self._n_points # reference initial values self._ref_initial_pars = np.array([1.0, 0.0]) self._ref_x = np.arange(self._n_points) self._ref_initial_y_model = line_xy_model(self._ref_x, *self._ref_initial_pars) self._ref_initial_xy_model = np.array( [self._ref_x, self._ref_initial_y_model]) # reference matrices/errors self._ref_y_error_vector = np.ones(self._n_points) * 0.1 self._ref_y_error_matrix = np.diag(self._ref_y_error_vector**2) self._ref_x_error_vector = np.ones(self._n_points) self._ref_x_error_matrix = np.diag(self._ref_x_error_vector**2) def line_xy_model_derivative(x, a=1.0, b=0.0): return a _fp = line_xy_model_derivative(self._ref_x, *self._ref_initial_pars) self._ref_projected_xy_matrix = ( self._ref_y_error_matrix + self._ref_x_error_matrix * np.outer(_fp, _fp)) self._ref_projected_xy_errors = np.diag( np.sqrt(self._ref_projected_xy_matrix)) # fit data self._ref_y_data = self._ref_initial_y_model + self._y_jitter self._ref_xy_data = np.array([self._ref_x, self._ref_y_data]) # pre-fit cost value self._ref_initial_cost = self._default_cost_function( self._ref_y_data, self._ref_initial_y_model, np.linalg.inv(self._ref_projected_xy_matrix), self._ref_initial_pars, [], ) # reference fit result values self._nominal_fit_result_pars = np.array([1.02590618, -0.00967721]) self._nominal_fit_result_y_model = line_xy_model( self._ref_x, *self._nominal_fit_result_pars) self._nominal_fit_result_xy_model = np.array( [self._ref_x, self._nominal_fit_result_y_model]) self._nominal_fit_result_projected_xy_matrix = 1.0624835 * np.eye( self._n_points) self._nominal_fit_result_projected_xy_errors = np.diag( np.sqrt(self._nominal_fit_result_projected_xy_matrix)) self._nominal_fit_result_cost = self._default_cost_function( self._ref_y_data, self._nominal_fit_result_y_model, np.linalg.inv(self._nominal_fit_result_projected_xy_matrix), self._nominal_fit_result_pars, [], ) # helper dict with all reference property values self._ref_prop_dict = dict( parameter_values=self._ref_initial_pars, x_data=self._ref_x, x_model=self._ref_x, y_data=self._ref_y_data, y_model=self._ref_initial_y_model, data=self._ref_xy_data, model=self._ref_initial_xy_model, did_fit=False, x_data_cov_mat=self._ref_x_error_matrix, y_data_cov_mat=self._ref_y_error_matrix, x_data_cov_mat_inverse=np.linalg.inv(self._ref_x_error_matrix), y_data_cov_mat_inverse=np.linalg.inv(self._ref_y_error_matrix), x_data_cor_mat=np.eye(self._n_points), y_data_cor_mat=np.eye(self._n_points), x_data_error=self._ref_x_error_vector, y_data_error=self._ref_y_error_vector, cost_function_value=self._ref_initial_cost, total_cov_mat=self._ref_projected_xy_matrix, total_error=self._ref_projected_xy_errors, )