Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unused variable + multiple RuntimeWarning #4

Closed
Gabriel-p opened this issue Jun 20, 2017 · 2 comments
Closed

Unused variable + multiple RuntimeWarning #4

Gabriel-p opened this issue Jun 20, 2017 · 2 comments

Comments

@Gabriel-p
Copy link

I'm testing the code on some random data:

def getData(c):
    """Initiate random data."""
    import random
    random.seed(9001)
    np.random.seed(117)
    x = np.array([0, 1, 2, 3, 4, 5])
    y = np.array([i**2 + random.random() for i in x])
    xerr = c * np.array([random.random() for i in x])
    yerr = c * np.array([random.random() for i in x])
    return x, y, xerr, yerr

x, y, xerr, yerr = getData(1.)
cov = np.zeros(len(x))
N_boot = 1000
a, b, erra, errb, covab = bcesboot(x, xerr, y, yerr, cov, N_boot)

Two thing I noticed:

  1. There is an unused covar_ba variable defined in bces().
  2. If I use bcesboot() with N_boot=1000 I get no warnings, but if I increase it to N=10000 (or more) I get multiple RuntimeWarning:
Bootstrapping progress:
bces_orig.py:54: RuntimeWarning: divide by zero encountered in double_scalars
  a[1] = (y2.var() - sig22var)/(covar_y1y2 - sig12var)	# X|Y
bces_orig.py:55: RuntimeWarning: invalid value encountered in double_scalars
  a[2] = ( a[0]*a[1] - 1.0 + numpy.sqrt((1.0 + a[0]**2)*(1.0 + a[1]**2)) ) / (a[0]+a[1])	# bisector
bces_orig.py:60: RuntimeWarning: divide by zero encountered in double_scalars
  a[3] = 0.5*((a[1]-(1./a[0])) + sign*numpy.sqrt(4.+(a[1]-(1./a[0]))**2))	# orthogonal
bces_orig.py:60: RuntimeWarning: invalid value encountered in double_scalars
  a[3] = 0.5*((a[1]-(1./a[0])) + sign*numpy.sqrt(4.+(a[1]-(1./a[0]))**2))	# orthogonal
bces_orig.py:68: RuntimeWarning: invalid value encountered in subtract
  xi.append(	( (y2-y2.mean()) * (y2-a[1]*y1-b[1]) - y2err**2 ) / covar_y1y2	)	# X|Y
bces_orig.py:69: RuntimeWarning: invalid value encountered in multiply
  xi.append(	xi[0] * (1.+a[1]**2)*a[2] / ((a[0]+a[1])*numpy.sqrt((1.+a[0]**2)*(1.+a[1]**2))) + xi[1] * (1.+a[0]**2)*a[2] / ((a[0]+a[1])*numpy.sqrt((1.+a[0]**2)*(1.+a[1]**2)))	)	# bisector
bces_orig.py:70: RuntimeWarning: divide by zero encountered in double_scalars
  xi.append(	xi[0] * a[3]/(a[0]**2*numpy.sqrt(4.+(a[1]-1./a[0])**2)) + xi[1]*a[3]/numpy.sqrt(4.+(a[1]-1./a[0])**2)	)	# orthogonal
bces_orig.py:70: RuntimeWarning: invalid value encountered in double_scalars
  xi.append(	xi[0] * a[3]/(a[0]**2*numpy.sqrt(4.+(a[1]-1./a[0])**2)) + xi[1]*a[3]/numpy.sqrt(4.+(a[1]-1./a[0])**2)	)	# orthogonal
bces_orig.py:176: RuntimeWarning: invalid value encountered in double_scalars
  erra[i]=numpy.sqrt( 1./(nsim-1) * ( numpy.sum(am[:,i]**2)-nsim*(am[:,i].mean())**2 ))
bces_orig.py:177: RuntimeWarning: invalid value encountered in double_scalars
  errb[i]=numpy.sqrt( 1./(nsim-1) * ( numpy.sum(bm[:,i]**2)-nsim*(bm[:,i].mean())**2 ))
bces_orig.py:178: RuntimeWarning: invalid value encountered in double_scalars
  covab[i]=1./(nsim-1) * ( numpy.sum(am[:,i]*bm[:,i])-nsim*am[:,i].mean()*bm[:,i].mean() )
@rsnemmen
Copy link
Owner

I will look into it. Thanks for reporting.

@rsnemmen
Copy link
Owner

Dear @Gabriel-p,
Just wanted to let you know that I fixed this bug. This occurred for small datasets of just a few points, but now it is fixed in the latest version of the code. Give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants