[Python] Orthogonal Distance Regression (ODR) convergence on valid data

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I have some real data points, and I'm trying to use the ODR to fit linear regression and also output the uncertainty error of the slope.

    import numpy as np
    from scipy.odr import ODR, Model, RealData

    x_val = np.array([0.05300576, 0.1276298, 0.22689743, 0.3451362, 0.55099835,
    0.92277924, 0.99269201, 1.62359292, 1.95232633, 3.20494195])
    y_val = np.array([0.06512638, 0.14413284, 0.24883807, 0.3707653, 0.57590205,
    0.94093455, 1.00025777, 1.63620188, 1.94281715, 3.07502401])
    x_err = np.array([0.00979887, 0.01592455, 0.02224418, 0.0287039, 0.03868461,
    0.05485672, 0.0577478, 0.08268442, 0.09514979, 0.14098461])
    y_err = np.array([0.00451811, 0.00709279, 0.00988615, 0.01522987, 0.02465449,
    0.04240767, 0.05696369, 0.07861697, 0.11871893, 0.15987048])

    def f(B, x):
    return B[0] * x + B[1]

    model = Model(f)
    data = RealData(x_val, y_val, sx=x_err, sy=y_err)
    odr = ODR(data, model, beta0=[1., 0.])
    out = odr.run()
    out.pprint()


    The output returns:

    Beta: [1. 0.]
    Beta Std Error: [0. 0.]
    Beta Covariance: [[0. 0.]
    [0. 0.]]
    Residual Variance: 0.0
    Inverse Condition #: 0.0
    Reason(s) for Halting:
    Problem is not full rank at solution
    Sum of squares convergence


    Why is it failing?

    Continue reading...

Compartilhe esta Página