romspline/random_seeds.py
def small_spline(x, y, num, tol=1e-6, deg=None, rel=False, parallel=True, verbose=False):
  """Build reduced-order splines for a number of randomly selected
  input seed points for the purpose of finding the spline with the
  smallest such reduced data over the sampled seeds. The degree of
  the spline polynomial can also be varied.
  
  Input
  -----
    x        -- samples
    y        -- data to be downsampled
    num      -- number of sets of random initial seed points
    tol      -- L-infinity error tolerance for reduced-order spline 
                (default 1e-6)
    deg      -- degree of interpolating polynomials 
                (default None)
    rel      -- L-infinity error tolerance is relative to max abs of data?
                (default False)
    parallel -- parallelize the computation of each random seed set?
                (default True)
    verbose  -- print progress to screen?
                (default False)
  
  Output
  ------
  Reduced-order spline object with the smallest reduced data size
  for the seeds (and spline degrees) sampled.
  
  Comments
  --------
  If deg is None then polynomials of degrees 1-5 are also sampled, in
  addition to the random sets of initial seeds.
  """
  
  if deg is None:                  # Use all integers in [1,5]
    degs = range(1, 6)
  else:
    if len(np.shape(deg)) == 1:    # deg is a list or array
      degs = deg
    elif len(np.shape(deg)) == 0:  # deg is a number
      degs = [deg]
    else:
      raise Exception("Input for `deg` option not recognized.")
  for dd in degs:
    assert (dd in range(1,6)), "Expecting degree(s) to be one or more integers in [1,5]."
  
  size = len(x)+1  # Add 1 to guarantee that a smaller size will be found below
  
  for ii, dd in enumerate(degs):
    if verbose:
      print("Smallest spline for degree {} is...".format(dd),)
    
    # Sample from the set of all possible initial 
    # seeds for this polynomial degree
    rand = RandomSeeds(tol=tol, deg=dd, rel=rel)
    rand.make(x, y, num, parallel=parallel)
    
    if verbose:  # Print smallest size found in sample
      print(int(np.min(rand.sizes)))
    
    # Find smallest spline in the sample for this polynomial degree
    imin = np.argmin(rand.sizes)
    if rand.sizes[imin] < size:
      size = rand.sizes[imin]
      seed = rand.seeds[imin]
      degree = dd
  
  # Output the reduced-order spline object for the smallest case
  return greedy.ReducedOrderSpline(x, y, tol=tol, deg=degree, rel=rel, seeds=seed)
Build reduced-order splines for a number of randomly selected
  input seed points for the purpose of finding the spline with the
  smallest such reduced data over the sampled seeds. The degree of
  the spline polynomial can also be varied.
  
  Input
  -----
    x        -- samples
    y        -- data to be downsampled
    num      -- number of sets of random initial seed points
    tol      -- L-infinity error tolerance for reduced-order spline 
                (default 1e-6)
    deg      -- degree of interpolating polynomials 
                (default None)
    rel      -- L-infinity error tolerance is relative to max abs of data?
                (default False)
    parallel -- parallelize the computation of each random seed set?
                (default True)
    verbose  -- print progress to screen?
                (default False)
  
  Output
  ------
  Reduced-order spline object with the smallest reduced data size
  for the seeds (and spline degrees) sampled.
  
  Comments
  --------
  If deg is None then polynomials of degrees 1-5 are also sampled, in
  addition to the random sets of initial seeds.
  
Build reduced-order splines for a number of randomly selected
input seed points for the purpose of finding the spline with the
smallest such reduced data over the sampled seeds. The degree of
the spline polynomial can also be varied.

Input



Output

Reduced-order spline object with the smallest reduced data size
for the seeds (and spline degrees) sampled.

Comments

If deg is None then polynomials of degrees 1-5 are also sampled, in
addition to the random sets of initial seeds.
Build reduced - order splines for a number of randomly selected input seed points for the purpose of finding the spline with the smallest such reduced data over the sampled seeds . The degree of the spline polynomial can also be varied . Input Output Reduced - order spline object with the smallest reduced data size for the seeds ( and spline degrees ) sampled . Comments If deg is None then polynomials of degrees 1 - 5 are also sampled in addition to the random sets of initial seeds .
def small_spline(x, y, num, tol=1e-6, deg=None, rel=False, parallel=True, verbose=False):
  if deg is None:                  
    degs = range(1, 6)
  else:
    if len(np.shape(deg)) == 1:    
      degs = deg
    elif len(np.shape(deg)) == 0:  
      degs = [deg]
    else:
      raise Exception("Input for `deg` option not recognized.")
  for dd in degs:
    assert (dd in range(1,6)), "Expecting degree(s) to be one or more integers in [1,5]."
  size = len(x)+1  
  for ii, dd in enumerate(degs):
    if verbose:
      print("Smallest spline for degree {} is...".format(dd),)
    rand = RandomSeeds(tol=tol, deg=dd, rel=rel)
    rand.make(x, y, num, parallel=parallel)
    if verbose:  
      print(int(np.min(rand.sizes)))
    imin = np.argmin(rand.sizes)
    if rand.sizes[imin] < size:
      size = rand.sizes[imin]
      seed = rand.seeds[imin]
      degree = dd
  return greedy.ReducedOrderSpline(x, y, tol=tol, deg=degree, rel=rel, seeds=seed)
def small_spline ( x , y , num , tol = 1e-6 , deg = None , rel = False , parallel = True , verbose = False ) : if deg is None : degs = range ( 1 , 6 ) else : if len ( np . shape ( deg ) ) == 1 : degs = deg elif len ( np . shape ( deg ) ) == 0 : degs = [ deg ] else : raise Exception ( "Input for `deg` option not recognized." ) for dd in degs : assert ( dd in range ( 1 , 6 ) ) , "Expecting degree(s) to be one or more integers in [1,5]." size = len ( x ) + 1 for ii , dd in enumerate ( degs ) : if verbose : print ( "Smallest spline for degree {} is..." . format ( dd ) , ) rand = RandomSeeds ( tol = tol , deg = dd , rel = rel ) rand . make ( x , y , num , parallel = parallel ) if verbose : print ( int ( np . min ( rand . sizes ) ) ) imin = np . argmin ( rand . sizes ) if rand . sizes [ imin ] < size : size = rand . sizes [ imin ] seed = rand . seeds [ imin ] degree = dd return greedy . ReducedOrderSpline ( x , y , tol = tol , deg = degree , rel = rel , seeds = seed )
Build reduced-order splines for a number of randomly selected
input seed points for the purpose of finding the spline with the
smallest such reduced data over the sampled seeds.
Build reduced - order splines for a number of randomly selected input seed points for the purpose of finding the spline with the smallest such reduced data over the sampled seeds .
"""Build reduced-order splines for a number of randomly selected
  input seed points for the purpose of finding the spline with the
  smallest such reduced data over the sampled seeds. The degree of
  the spline polynomial can also be varied.
  
  Input
  -----
    x        -- samples
    y        -- data to be downsampled
    num      -- number of sets of random initial seed points
    tol      -- L-infinity error tolerance for reduced-order spline 
                (default 1e-6)
    deg      -- degree of interpolating polynomials 
                (default None)
    rel      -- L-infinity error tolerance is relative to max abs of data?
                (default False)
    parallel -- parallelize the computation of each random seed set?
                (default True)
    verbose  -- print progress to screen?
                (default False)
  
  Output
  ------
  Reduced-order spline object with the smallest reduced data size
  for the seeds (and spline degrees) sampled.
  
  Comments
  --------
  If deg is None then polynomials of degrees 1-5 are also sampled, in
  addition to the random sets of initial seeds.
  """ # Use all integers in [1,5] # deg is a list or array # deg is a number # Add 1 to guarantee that a smaller size will be found below # Sample from the set of all possible initial  # seeds for this polynomial degree # Print smallest size found in sample # Find smallest spline in the sample for this polynomial degree # Output the reduced-order spline object for the smallest case
x
y
num
tol
deg
rel
parallel
verbose