コード例 #1
0
 def compare_jacobian(self, fit_function, ndim, isotropic, n, groups=None,
                      custom_param_mode=None):
     ff = FitFunctions(fit_function, ndim, isotropic)
     param_mode = {param: 'var' for param in ff.params}
     param_mode['background'] = 'cluster'
     if custom_param_mode is not None:
         param_mode.update(custom_param_mode)
     ff = FitFunctions(fit_function, ndim, isotropic, param_mode=param_mode)
     params = np.random.random((n, len(ff.params))) * 10
     residual, jacobian = self.get_residual(ff, n, params, groups)
     vect = vect_from_params(params, ff.modes, groups, operation=np.mean)
     actual = jacobian(vect)
     expected = approx_jacobian(vect, residual, EPSILON)[0]
     assert_allclose(actual, expected, rtol=RTOL, atol=ATOL)
コード例 #2
0
    def test_2D_gauss(self):
        def gauss(p, y, x):
            background, signal, yc, xc, size = p
            return background + signal*np.exp(-((y - yc)**2/size**2 + (x - xc)**2/size**2))
        ff = FitFunctions('gauss', ndim=2, isotropic=True)
        params = np.array([[5, 200, 4, 5, 6]], dtype=np.float)

        image = np.random.random(self.repeats) * 200
        mesh = np.random.random((ff.ndim, self.repeats)) * 10
        masks = np.full((1, self.repeats), True, dtype=np.bool)

        residual, jacobian = ff.get_residual([image], [mesh], [masks], params)

        vect = vect_from_params(params, ff.modes, groups=None, operation=np.mean)

        actual = residual(vect)
        expected = np.sum((image - gauss(params[0], *mesh))**2) / self.repeats

        assert_allclose(actual, expected, atol=1E-7)