def getTheta(k, nTrials=100000):
  """
  Estimate a reasonable value of theta for this k.
  """
  theDots = np.zeros(nTrials)
  w1 = getSparseTensor(k, k, nTrials, fixedRange=1.0/k)
  for i in range(nTrials):
    theDots[i] = w1[i].dot(w1[i])

  dotMean = theDots.mean()
  print("k=", k, "min/mean/max diag of w dot products",
        theDots.min(), dotMean, theDots.max())

  theta = dotMean / 2.0
  print("Using theta as mean / 2.0 = ", theta)

  return theta, theDots
Estimate a reasonable value of theta for this k.