예제 #1
0
파일: lhs.py 프로젝트: zoidy/puq
    def __init__(self,
                 params,
                 num,
                 ds=False,
                 response=True,
                 iteration_cb=None):
        PSweep.__init__(self, iteration_cb)
        self.params = params
        num = int(num)
        self.num = num
        self.ds = ds
        self.response = response
        self._start_at = 0

        if self.response:
            # To generate a complete response surface, use Uniform distributions
            # with the same range as the original distributions.
            for p in self.params:
                if ds:
                    p.values = UniformPDF(*p.pdf.range).ds(num)
                else:
                    p.values = UniformPDF(*p.pdf.range).lhs(num)
        else:
            for p in self.params:
                if ds:
                    p.values = p.pdf.ds(num)
                else:
                    p.values = p.pdf.lhs(num)
예제 #2
0
파일: parameter.py 프로젝트: wang159/puq
class UniformParameter(Parameter):
    '''
    Class implementing a Parameter with a Uniform distribution.

    Args:
      name: Name of the parameter. This should be a short name,
        like a variable.
      description:  A longer description of the parameter.
      kwargs: Keyword args.  Valid args are:

        ======== ============================
        Property Description
        ======== ============================
        mean     The mean of the distribution
        max      The maximum
        min      The minimum
        ======== ============================

    You **must** specify two of the above properties. If you
    give all three, they will be checked for consistency.
    :math:`mean = (min + max)/2`
    '''
    def __init__(self, name, description, **kwargs):
        Parameter.__init__(self, name, description, **kwargs)
        self.pdf = UniformPDF(**self.kwargs)

    def __str__(self):
        return "UniformParameter %s (%s)\n\t%s" %\
            (self.name, self.description, self.pdf.__str__())
예제 #3
0
 def extend(self, num):
     if num <= 0:
         print "Monte Carlo extend requires a valid num argument."
         raise ValueError
     for p in self.params:
         if self.response:
             p.values = np.concatenate(
                 (p.values, UniformPDF(*p.pdf.range).random(num)))
         else:
             p.values = np.concatenate((p.values, p.pdf.random(num)))
     self._start_at = self.num
     self.num += num
예제 #4
0
    def extend(self, num=None):
        if not hasattr(self, 'ds') or not self.ds:
            print("You must use Descriptive Sampling to extend.")
            sys.exit(1)

        print("Extending Descriptive Sampling run to %s samples." % (self.num * 3))
        for p in self.params:
            if self.response:
                v = np.sort(UniformPDF(*p.pdf.range).ds(self.num * 3))
            else:
                v = np.sort(p.pdf.ds(self.num * 3))
            # remove the ones we already did
            v = np.concatenate((v[0::3], v[2::3]))
            p.values = np.concatenate((p.values, np.random.permutation(v)))
        self._start_at = self.num
        self.num *= 3
예제 #5
0
파일: parameter.py 프로젝트: wang159/puq
 def __init__(self, name, description, **kwargs):
     Parameter.__init__(self, name, description, **kwargs)
     self.pdf = UniformPDF(**self.kwargs)
예제 #6
0
파일: parameter.py 프로젝트: zoidy/puq
 def __init__(self, name, description, **kwargs):
     self.name = self.check_name(name)
     self.description = description
     self.caldata = kwargs.pop('caldata', None)
     self.pdf = UniformPDF(**kwargs)