diff --git a/.github/workflows/binder.yml b/.github/workflows/binder.yml new file mode 100644 index 00000000..460f0fef --- /dev/null +++ b/.github/workflows/binder.yml @@ -0,0 +1,15 @@ +name: binder +on: + push: + branches: + - develop + +jobs: + Create-MyBinderOrg-Cache: + runs-on: ubuntu-latest + steps: + - name: cache binder build on mybinder.org + uses: jupyterhub/repo2docker-action@master + with: + NO_PUSH: true + MYBINDERORG_TAG: ${{ github.event.ref }} # This builds the container on mybinder.org with the branch that was pushed on. diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 4c074906..9db158d3 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -13,15 +13,15 @@ jobs: pytest: runs-on: ${{ matrix.os }} strategy: - fail-fast: true + fail-fast: true matrix: os: [ubuntu-latest] python-version: ["3.7", "3.8", "3.9", "3.10"] include: - os: macos-latest - python-version: 3.9 + python-version: 3.9 - os: windows-latest - python-version: 3.9 + python-version: 3.9 steps: - name: Checkout source diff --git a/pyerrors/fits.py b/pyerrors/fits.py index 420d3da0..512a57cb 100644 --- a/pyerrors/fits.py +++ b/pyerrors/fits.py @@ -264,9 +264,19 @@ def total_least_squares(x, y, func, silent=False, **kwargs): fitp = out.beta try: - hess_inv = np.linalg.pinv(jacobian(jacobian(odr_chisquare))(np.concatenate((fitp, out.xplus.ravel())))) + hess = jacobian(jacobian(odr_chisquare))(np.concatenate((fitp, out.xplus.ravel()))) except TypeError: raise Exception("It is required to use autograd.numpy instead of numpy within fit functions, see the documentation for details.") from None + condn = np.linalg.cond(hess) + if condn > 1e8: + warnings.warn("Hessian matrix might be ill-conditioned ({0:1.2e}), error propagation might be unreliable.\n \ + Maybe try rescaling the problem such that all parameters are of O(1).".format(condn), RuntimeWarning) + try: + hess_inv = np.linalg.inv(hess) + except np.linalg.LinAlgError: + raise Exception("Cannot invert hessian matrix.") + except Exception: + raise Exception("Unkown error in connection with Hessian inverse.") def odr_chisquare_compact_x(d): model = func(d[:n_parms], d[n_parms:n_parms + m].reshape(x_shape)) @@ -542,9 +552,19 @@ def _standard_fit(x, y, func, silent=False, **kwargs): fitp = fit_result.x try: - hess_inv = np.linalg.pinv(jacobian(jacobian(chisqfunc))(fitp)) + hess = jacobian(jacobian(chisqfunc))(fitp) except TypeError: raise Exception("It is required to use autograd.numpy instead of numpy within fit functions, see the documentation for details.") from None + condn = np.linalg.cond(hess) + if condn > 1e8: + warnings.warn("Hessian matrix might be ill-conditioned ({0:1.2e}), error propagation might be unreliable.\n \ + Maybe try rescaling the problem such that all parameters are of O(1).".format(condn), RuntimeWarning) + try: + hess_inv = np.linalg.inv(hess) + except np.linalg.LinAlgError: + raise Exception("Cannot invert hessian matrix.") + except Exception: + raise Exception("Unkown error in connection with Hessian inverse.") if kwargs.get('correlated_fit') is True: def chisqfunc_compact(d):