コード例 #1
0
ファイル: filters.py プロジェクト: vishalbelsare/mystic
 def func(x, z=None):
     if not hasattr(mask, '__call__'):
         _mask = mask
     else:
         _mask = mask(x, z)
     if z is None and hasattr(x, '_x') and hasattr(x, '_y'):
         from copy import copy
         m = copy(x)
         mon = True
     else:
         from mystic.monitors import Monitor
         m = Monitor()
         m._x, m._y = x, z
         mon = False
     ax = True if hasattr(m._x, 'tolist') else False
     ay = True if hasattr(m._y, 'tolist') else False
     from numpy import asarray
     m._x = asarray(m._x)[_mask]
     m._y = asarray(m._y)[_mask]
     if not ax: m._x = m._x.tolist()
     if not ay: m._y = m._y.tolist()
     if mon:
         try:
             ai = True if hasattr(m._id, 'tolist') else False
             m._id = array(m._id)[_mask]
             if not ai: m._id = m._id.tolist()
         except IndexError:
             pass  #XXX: m._id = []
         return m
     return m._x, m._y
コード例 #2
0
ファイル: munge.py プロジェクト: agamdua/mystic
def write_monitor(steps, energy, id=[]):
  from mystic.monitors import Monitor
  mon = Monitor()
  mon._x = steps[:]
  mon._y = energy[:]
  mon._id = id[:]
  return mon
コード例 #3
0
def write_monitor(steps, energy, id=[]):
    from mystic.monitors import Monitor
    mon = Monitor()
    mon._x = steps[:]
    mon._y = energy[:]
    mon._id = id[:]
    return mon
コード例 #4
0
def extrapolate(x, z=None, method=None, mins=None, maxs=None, **kwds):
    '''extrapolate a bounding-box for the given points

    Input:
      x: an array of shape (npts, dim) or (npts,)
      z: an array of shape (npts,)
      method: a function f(x) to generate new points; if None, use f(x) = nan
      mins: a list of floats defining minima of the bounding box, or None
      maxs: a list of floats defining maxima of the bounding box, or None
      all: if True, include the initial (x,z) points in the return

    Output:
      a tuple of (x,z) containing the requested boundbox points

    NOTE:
      if z is None, return a tuple (x,) with the requested boundbox points.

    NOTE:
      if mins is None, then use the minima found in x. Similarly for maxs.

    NOTE:
      method can take a function, None, a boolean, or a string. If method is
      True, interpolate a cost function using interpf with method='thin_plate'
      (or 'rbf' if scipy is not found). If method is False, return the original
      input. Alternately, method can be any one of ('rbf','linear','cubic',
      'nearest','inverse','gaussian','multiquadric','quintic','thin_plate').
    '''
    kwds.setdefault('all', True)
    import numpy as np
    output = True
    if z is None:
        z = np.nan * np.ones(len(x))
        output = False
        method = None  # ignore method
    xtype = getattr(x, 'dtype', None)
    ztype = getattr(z, 'dtype', None)
    if xtype: x = x.tolist()
    if ztype: z = z.tolist()
    if method:
        if method is True:
            method = 'thin_plate'
        if not hasattr(method, '__call__'):
            method = _to_objective(interpf(x, z, method=method))
    from mystic.monitors import Monitor
    mon = Monitor()
    mon._x = x
    mon._y = z
    if (method is None) or method:
        mon = _boundbox(mon, fx=method, mins=mins, maxs=maxs, **kwds)
    x = np.array(mon._x, dtype=xtype) if xtype else mon._x
    z = np.array(mon._y, dtype=ztype) if ztype else mon._y
    return (x, z) if output else x