def leastsquare(measured_vals, updated_model, weights, x, y=None):
 if (y is None):
  model_vals = updated_model(x)
 else:
  model_vals = updated_model(x, y)
 if (weights is None):
  return np.sum(((model_vals - measured_vals) ** 2))
 else:
  return np.sum(((weights * (model_vals - measured_vals)) ** 2))

def leastsquare ( measured_vals , updated_model , weights , x , y = None ) : if ( y is None ) : model_vals = updated_model ( x ) else : model_vals = updated_model ( x , y ) if ( weights is None ) : return np . sum ( ( ( model_vals - measured_vals ) ** 2 ) ) else : return np . sum ( ( ( weights * ( model_vals - measured_vals ) ) ** 2 ) )
least square statistic with optional weights .