romspline/cross_validation.py
def _cross_validation(x, y, validation, training, tol=1e-6, rel=False, deg=5):
  """K-fold cross validation on a given partition
  
  Input
  -----
    x          -- samples
    y          -- data values at samples
    validation -- validation subset of data indexes
    training   -- training subset of data indexes
    tol        -- L-infinity error tolerance for reduced-order spline 
                  (default 1e-6)
    rel        -- L-infinity error tolerance is relative to max abs of data?
                  (default False)
    deg        -- degree of interpolating polynomials 
                  (default 5)
  
  Output
  ------
    sample index where largest validation error occurs
    largest validation error
  
  Comment
  -------
  The union of the validation and training subsets must contain all the
  data array indexes.
  """
  
  assert len(x) == len(y), "Expecting x and y arrays to have same lengths."
  assert len(np.hstack([validation, training])) == len(x), "Expecting union of validation and training sets to have same lengths as x and y arrays."
  
  # Form trial data
  x_training = x[training]
  y_training = y[training]
  
  # Build trial spline
  spline = greedy._greedy(x_training, y_training, tol=tol, rel=rel, deg=deg)[0]
  
  # Compute L-infinity errors between training and data in validation partition
  errors = np.abs(spline(x[validation]) - y[validation])
  
  return errors, np.max(errors), validation[np.argmax(errors)]
K-fold cross validation on a given partition
  
  Input
  -----
    x          -- samples
    y          -- data values at samples
    validation -- validation subset of data indexes
    training   -- training subset of data indexes
    tol        -- L-infinity error tolerance for reduced-order spline 
                  (default 1e-6)
    rel        -- L-infinity error tolerance is relative to max abs of data?
                  (default False)
    deg        -- degree of interpolating polynomials 
                  (default 5)
  
  Output
  ------
    sample index where largest validation error occurs
    largest validation error
  
  Comment
  -------
  The union of the validation and training subsets must contain all the
  data array indexes.
  
K-fold cross validation on a given partition
Input



Output

sample index where largest validation error occurs
largest validation error

Comment

The union of the validation and training subsets must contain all the
data array indexes.
K - fold cross validation on a given partition Input Output sample index where largest validation error occurs largest validation error Comment The union of the validation and training subsets must contain all the data array indexes .
def _cross_validation(x, y, validation, training, tol=1e-6, rel=False, deg=5):
  assert len(x) == len(y), "Expecting x and y arrays to have same lengths."
  assert len(np.hstack([validation, training])) == len(x), "Expecting union of validation and training sets to have same lengths as x and y arrays."
  x_training = x[training]
  y_training = y[training]
  spline = greedy._greedy(x_training, y_training, tol=tol, rel=rel, deg=deg)[0]
  errors = np.abs(spline(x[validation]) - y[validation])
  return errors, np.max(errors), validation[np.argmax(errors)]
def _cross_validation ( x , y , validation , training , tol = 1e-6 , rel = False , deg = 5 ) : assert len ( x ) == len ( y ) , "Expecting x and y arrays to have same lengths." assert len ( np . hstack ( [ validation , training ] ) ) == len ( x ) , "Expecting union of validation and training sets to have same lengths as x and y arrays." x_training = x [ training ] y_training = y [ training ] spline = greedy . _greedy ( x_training , y_training , tol = tol , rel = rel , deg = deg ) [ 0 ] errors = np . abs ( spline ( x [ validation ] ) - y [ validation ] ) return errors , np . max ( errors ) , validation [ np . argmax ( errors ) ]
K-fold cross validation on a given partition
Input
K - fold cross validation on a given partition Input
"""K-fold cross validation on a given partition
  
  Input
  -----
    x          -- samples
    y          -- data values at samples
    validation -- validation subset of data indexes
    training   -- training subset of data indexes
    tol        -- L-infinity error tolerance for reduced-order spline 
                  (default 1e-6)
    rel        -- L-infinity error tolerance is relative to max abs of data?
                  (default False)
    deg        -- degree of interpolating polynomials 
                  (default 5)
  
  Output
  ------
    sample index where largest validation error occurs
    largest validation error
  
  Comment
  -------
  The union of the validation and training subsets must contain all the
  data array indexes.
  """ # Form trial data # Build trial spline # Compute L-infinity errors between training and data in validation partition
x
y
validation
training
tol
rel
deg