Example #1
0
    def short(self, data=None, L=None, blamelist=False, pairs=True, all=False, raw=False, **kwds):
        """check for shortness with respect to given data (or self)

Inputs:
    data -- a collection of data points (if None, use the dataset itself)
    L -- the lipschitz constant, if different from that of the dataset itself 
    blamelist -- if True, report which points are infeasible
    pairs -- if True, report indices of infeasible points
    all -- if True, report results for each point (opposed to all points)
    raw -- if True, report numerical results (opposed to boolean results)

Additional Inputs:
    tol -- maximum acceptable deviation from shortness
    cutoff -- zero out distances less than cutoff; typically: tol, 0.0, or None

Notes:
    Each point x,y can be thought to have an associated double-cone with slope
    equal to the lipschitz constant. Shortness with respect to another point is
    defined by the first point not being inside the cone of the second. We can
    allow for some error in shortness, a short tolerance 'tol', for which the
    point x,y is some acceptable y-distance inside the cone. While very tightly
    related, cutoff and tol play distinct roles; tol is subtracted from
    calculation of the lipschitz_distance, while cutoff zeros out the value
    of any element less than the cutoff.
"""
        tol = kwds["tol"] if "tol" in kwds else 0.0  # get tolerance in y
        # default is to zero out distances less than tolerance
        cutoff = kwds["cutoff"] if "cutoff" in kwds else tol
        if cutoff is True:
            cutoff = tol
        elif cutoff is False:
            cutoff = None

        if L is None:
            L = self.lipschitz
        if data is None:
            data = self
        from mystic.math.distance import lipschitz_distance, is_feasible

        # calculate the shortness
        Rv = lipschitz_distance(L, self, data, **kwds)
        ld = is_feasible(Rv, cutoff)
        if raw:
            x = Rv
        else:
            x = ld
        if not blamelist:
            return ld.all() if not all else x
        if pairs:
            return _fails(ld)
        # else lookup failures
        return _fails(ld, data)
Example #2
0
 def cost(rv):
   """compute cost from a 1-d array of model parameters,
   where:  cost = | sum(lipschitz_distance) | """
   _data = dataset()
   _pm = scenario()
   _pm.load(rv, pts)      # here rv is param: w,x,y
   if not long_form:
     positions = _pm.select(*range(npts))
   else: positions = _pm.positions
   _data.load( data.coords, data.values )                   # LOAD static
   if _self:
     _data.load( positions, _pm.values )                    # LOAD dynamic
   _data.lipschitz = data.lipschitz                         # LOAD L
   Rv = lipschitz_distance(_data.lipschitz, _pm, _data, tol=cutoff, **kwds)
   v = infeasibility(Rv, cutoff)
   return abs(sum(v))
Example #3
0
 def cost(rv):
   """compute cost from a 1-d array of model parameters,
   where:  cost = | sum(lipschitz_distance) | """
   _data = dataset()
   _pm = scenario()
   _pm.load(rv, pts)      # here rv is param: w,x,y
   if not long_form:
     positions = _pm.select(*range(npts))
   else: positions = _pm.positions
   _data.load( data.coords, data.values )                   # LOAD static
   if _self:
     _data.load( positions, _pm.values )                    # LOAD dynamic
   _data.lipschitz = data.lipschitz                         # LOAD L
   Rv = lipschitz_distance(_data.lipschitz, _pm, _data, tol=cutoff, **kwds)
   v = infeasibility(Rv, cutoff)
   return abs(sum(v))
Example #4
0
  def short(self, data=None, L=None, blamelist=False, pairs=True, \
                                     all=False, raw=False, **kwds):
    """check for shortness with respect to given data (or self)

Inputs:
    data -- a collection of data points (if None, use the dataset itself)
    L -- the lipschitz constant, if different from that of the dataset itself 
    blamelist -- if True, report which points are infeasible
    pairs -- if True, report indicies of infeasible points
    all -- if True, report results for each point (opposed to all points)
    raw -- if True, report numerical results (opposed to boolean results)

Additional Inputs:
    tol -- maximum acceptable deviation from shortness
    cutoff -- zero out distances less than cutoff; typically: tol, 0.0, or None

Notes:
    Each point x,y can be thought to have an associated double-cone with slope
    equal to the lipschitz constant. Shortness with respect to another point is
    defined by the first point not being inside the cone of the second. We can
    allow for some error in shortness, a short tolerance 'tol', for which the
    point x,y is some acceptable y-distance inside the cone. While very tightly
    related, cutoff and tol play distinct roles; tol is subtracted from
    calculation of the lipschitz_distance, while cutoff zeros out the value
    of any element less than the cutoff.
"""
    tol = kwds['tol'] if 'tol' in kwds else 0.0 # get tolerance in y
    # default is to zero out distances less than tolerance
    cutoff = kwds['cutoff'] if 'cutoff' in kwds else tol
    if cutoff is True: cutoff = tol
    elif cutoff is False: cutoff = None

    if L is None: L = self.lipschitz
    if data is None: data = self
    from mystic.math.distance import lipschitz_distance, is_feasible
    # calculate the shortness
    Rv = lipschitz_distance(L, self, data, **kwds)
    ld = is_feasible(Rv, cutoff)
    if raw:
      x = Rv
    else:
      x = ld
    if not blamelist: return ld.all() if not all else x
    if pairs: return _fails(ld)
    # else lookup failures
    return _fails(ld, data)
Example #5
0
  def short(self, data=None, L=None, blamelist=False, pairs=True, \
                                     all=False, raw=False, **kwds):
    """check for shortness with respect to given data (or self)

Args:
    data (list, default=None): a list of data points, or the dataset itself.
    L (float, default=None): the lipschitz constant, or the dataset's constant.
    blamelist (bool, default=False): if True, indicate the infeasible points.
    pairs (bool, default=True): if True, indicate indices of infeasible points.
    all (bool, default=False): if True, get results for each individual point.
    raw (bool, default=False): if False, get boolean results (i.e. non-float).
    tol (float, default=0.0): maximum acceptable deviation from shortness.
    cutoff (float, default=tol): zero out distances less than cutoff.

Notes:
    Each point x,y can be thought to have an associated double-cone with slope
    equal to the lipschitz constant. Shortness with respect to another point is
    defined by the first point not being inside the cone of the second. We can
    allow for some error in shortness, a short tolerance *tol*, for which the
    point x,y is some acceptable y-distance inside the cone. While very tightly
    related, *cutoff* and *tol* play distinct roles; *tol* is subtracted from
    calculation of the lipschitz_distance, while *cutoff* zeros out the value
    of any element less than the *cutoff*.
"""
    tol = kwds['tol'] if 'tol' in kwds else 0.0 # get tolerance in y
    # default is to zero out distances less than tolerance
    cutoff = kwds['cutoff'] if 'cutoff' in kwds else tol
    if cutoff is True: cutoff = tol
    elif cutoff is False: cutoff = None

    if L is None: L = self.lipschitz
    if data is None: data = self
    from mystic.math.distance import lipschitz_distance, is_feasible
    # calculate the shortness
    Rv = lipschitz_distance(L, self, data, **kwds)
    ld = is_feasible(Rv, cutoff)
    if raw:
      x = Rv
    else:
      x = ld
    if not blamelist: return ld.all() if not all else x
    if pairs: return _fails(ld)
    # else lookup failures
    return _fails(ld, data)
Example #6
0
    def short(self, data=None, L=None, blamelist=False, pairs=True, \
                                       all=False, raw=False, **kwds):
        """check for shortness with respect to given data (or self)

Args:
    data (list, default=None): a list of data points, or the dataset itself.
    L (float, default=None): the lipschitz constant, or the dataset's constant.
    blamelist (bool, default=False): if True, indicate the infeasible points.
    pairs (bool, default=True): if True, indicate indices of infeasible points.
    all (bool, default=False): if True, get results for each individual point.
    raw (bool, default=False): if False, get boolean results (i.e. non-float).
    tol (float, default=0.0): maximum acceptable deviation from shortness.
    cutoff (float, default=tol): zero out distances less than cutoff.

Notes:
    Each point x,y can be thought to have an associated double-cone with slope
    equal to the lipschitz constant. Shortness with respect to another point is
    defined by the first point not being inside the cone of the second. We can
    allow for some error in shortness, a short tolerance *tol*, for which the
    point x,y is some acceptable y-distance inside the cone. While very tightly
    related, *cutoff* and *tol* play distinct roles; *tol* is subtracted from
    calculation of the lipschitz_distance, while *cutoff* zeros out the value
    of any element less than the *cutoff*.
"""
        tol = kwds['tol'] if 'tol' in kwds else 0.0  # get tolerance in y
        # default is to zero out distances less than tolerance
        cutoff = kwds['cutoff'] if 'cutoff' in kwds else tol
        if cutoff is True: cutoff = tol
        elif cutoff is False: cutoff = None

        if L is None: L = self.lipschitz
        if data is None: data = self
        from mystic.math.distance import lipschitz_distance, is_feasible
        # calculate the shortness
        Rv = lipschitz_distance(L, self, data, **kwds)
        ld = is_feasible(Rv, cutoff)
        if raw:
            x = Rv
        else:
            x = ld
        if not blamelist: return ld.all() if not all else x
        if pairs: return _fails(ld)
        # else lookup failures
        return _fails(ld, data)
Example #7
0
  pts = (2,2,2)
  from mystic.math.legacydata import dataset
  data = dataset()
  data.load(bc, bv)
  data.lipschitz = L
  pm = scenario()
  pm.load(a, pts)
  pc = pm.positions
  pv = pm.values
  #---
  _data = dataset()
  _data.load(bc, bv)
  _data.load(pc, pv)
  _data.lipschitz = data.lipschitz
  from numpy import sum
  ans = sum(lipschitz_distance(L, pm, _data))
  print "original: %s @ %s\n" % (ans, a)
 #print "pm: %s" % pm
 #print "data: %s" % data
  #---
  lb = [0,.5,-100,-100,  0,.5,-100,-100,  0,.5,-100,-100,   0,0,0,0,0,0,0,0]
  ub = [.5,1, 100, 100,  .5,1, 100, 100,  .5,1, 100, 100,   9,9,9,9,9,9,9,9]
  bounds = (lb,ub)

  _constrain = mean_y_norm_wts_constraintsFactory((y_mean,y_buffer), pts)
  results = impose_feasible(feasability, data, guess=pts, tol=deviation, \
                            bounds=bounds, constraints=_constrain)
  from mystic.math.measures import mean
  print "solved: %s" % results.flatten(all=True)
  print "mean(y): %s >= %s" % (mean(results.values, results.weights), y_mean)
  print "sum(wi): %s == 1.0" % [sum(w) for w in results.wts]
Example #8
0
  pts = (2,2,2)
  from mystic.math.legacydata import dataset
  data = dataset()
  data.load(bc, bv)
  data.lipschitz = L
  pm = scenario()
  pm.load(a, pts)
  pc = pm.positions
  pv = pm.values
  #---
  _data = dataset()
  _data.load(bc, bv)
  _data.load(pc, pv)
  _data.lipschitz = data.lipschitz
  from numpy import sum
  ans = sum(lipschitz_distance(L, pm, _data))
  print "original: %s @ %s\n" % (ans, a)
 #print "pm: %s" % pm
 #print "data: %s" % data
  #---
  lb = [0,.5,-100,-100,  0,.5,-100,-100,  0,.5,-100,-100,   0,0,0,0,0,0,0,0]
  ub = [.5,1, 100, 100,  .5,1, 100, 100,  .5,1, 100, 100,   9,9,9,9,9,9,9,9]
  bounds = (lb,ub)

  _constrain = mean_y_norm_wts_constraintsFactory((y_mean,y_buffer), pts)
  results = impose_feasible(feasability, data, guess=pts, tol=deviation, \
                            bounds=bounds, constraints=_constrain)
  from mystic.math.measures import mean
  print "solved: %s" % results.flatten(all=True)
  print "mean(y): %s >= %s" % (mean(results.values, results.weights), y_mean)
  print "sum(wi): %s == 1.0" % [sum(w) for w in results.wts]