Example #1
0
class Model(base.Model):

   parms_default = u.copyupdate(base.Model.parms_default,
                                { 'fail_interval': 7,
                                  'do_nothing_func': foo })

   def build(self):
      self.warn_if_parallel()
      UTM_18N = 32618  # work in UTM for sane units (meters) on buffering
      manhattan = geos.Point((584939, 4509087), srid=UTM_18N)
      manhattan_poly = manhattan.buffer(9500)
      brooklyn_poly = geos.Point((588618, 4497627), srid=UTM_18N).buffer(5000)
      bronx_poly = geos.Point((593911, 4521284), srid=UTM_18N).buffer(2000)
      queens_poly = geos.Point((595675, 4511623), srid=UTM_18N).buffer(1000)

      multiregion = geos.MultiPolygon((manhattan_poly,
                                       brooklyn_poly,
                                       bronx_poly,
                                       queens_poly), srid=manhattan_poly.srid)
      self.pred_region = multiregion.cascaded_union
      self.best_point = manhattan

   def locate(self, tokens, coverage):
      if (self.parms['fail_interval'] > 0
          and u.rand.random() < 1.0/self.parms['fail_interval']):
         return None
      else:
         le = Location_Estimate(point=(self.pred_region, self.best_point),
                                srid=self.srid)
         le.prepare(coverage)
         return le
Example #2
0
 def parms_init(class_, parms, log_parms=False):
     '''Initialize the model parameters with parms. If any parameters remain
      with a value of None, or if anything in parms is not also in the
      default parameters, raise ValueError. WARNING: Of course, you can't
      have multiple instances of the same class with different parameters
      in the same process.'''
     parms = parms.copy()
     # check for bogus parameters
     for k in parms.keys():
         if (k not in class_.parms_default):
             raise ValueError('parameter %s is not supported' % (k))
     # munge in functions, if they exist
     for (k, v) in parms.items():
         if (isinstance(v, str)):
             try:
                 parms[k] = getattr(sys.modules[class_.__module__], v)
             except AttributeError:
                 pass
     # update parms class attribute
     class_.parms = u.copyupdate(class_.parms_default, parms)
     # print a report
     if (log_parms):
         l.info('model parameters:')
         # note: spacing matches model_test.Test_Sequence.main()
         for (k, v) in sorted(class_.parms.items()):
             l.info('  %s: %*s %s' % (k, 19 - len(k), ' ', str(v)))
     # check for missing parameters
     if (None in iter(class_.parms.values())):
         raise ValueError('model parameter with value None')
Example #3
0
File: base.py Project: reidpr/quac
 def parms_init(class_, parms, log_parms=False):
    '''Initialize the model parameters with parms. If any parameters remain
       with a value of None, or if anything in parms is not also in the
       default parameters, raise ValueError. WARNING: Of course, you can't
       have multiple instances of the same class with different parameters
       in the same process.'''
    parms = parms.copy()
    # check for bogus parameters
    for k in parms.keys():
       if (k not in class_.parms_default):
          raise ValueError('parameter %s is not supported' % (k))
    # munge in functions, if they exist
    for (k, v) in parms.items():
       if (isinstance(v, str)):
          try:
             parms[k] = getattr(sys.modules[class_.__module__], v)
          except AttributeError:
             pass
    # update parms class attribute
    class_.parms = u.copyupdate(class_.parms_default, parms)
    # print a report
    if (log_parms):
       l.info('model parameters:')
       # note: spacing matches model_test.Test_Sequence.main()
       for (k,v) in sorted(class_.parms.items()):
          l.info('  %s: %*s %s' % (k, 19 - len(k), ' ', str(v)))
    # check for missing parameters
    if (None in iter(class_.parms.values())):
       raise ValueError('model parameter with value None')
Example #4
0
File: gmm.py Project: shikhach/quac
class Model(base.Model):

    parms_default = u.copyupdate(base.Model.parms_default,
                                 MODEL_PARMS_DEFAULT())

    @classmethod
    def parms_init(class_, parms, **kwargs):
        super(Model, class_).parms_init(parms, **kwargs)
        # See above for more on this kludge.
        global model_parms
        model_parms = class_.parms