コード例 #1
0
    def select_samples(self, candidate, population_size, n):

        mysample = random.sample(xrange(population_size), n)
        #print 'select_samples: mysample = ', mysample
        if is_in(candidate, mysample):
            return self.select_samples(candidate, population_size, n)
        else:
            return mysample
コード例 #2
0
ファイル: opt.py プロジェクト: OrbitalMechanic/sherpa
    def select_samples(self, candidate, population_size, n):

        mysample = random.sample(xrange(population_size), n)
        # print 'select_samples: mysample = ', mysample
        if is_in(candidate, mysample):
            return self.select_samples(candidate, population_size, n)
        else:
            return mysample
コード例 #3
0
ファイル: fit.py プロジェクト: anetasie/sherpa-old
    def format(self):
        s = ""
        if (self.datasets != None):
            if len(self.datasets) == 1:
                s = 'Dataset               = %s\n' % str(self.datasets[0])
            else:
                s = 'Datasets              = %s\n' % str(self.datasets).strip("()")
        s += 'Confidence Method     = %s\n' % self.methodname
        if (self.iterfitname != None or self.iterfitname != 'none'):
            s += 'Iterative Fit Method  = %s\n' % self.iterfitname.capitalize()
        s += 'Fitting Method        = %s\n' % self.fitname
        s += 'Statistic             = %s\n' % self.statname 
        
        s += "%s %g-sigma (%2g%%) bounds:" % (self.methodname, self.sigma,
                                              self.percent)

        def myformat( hfmt, str, lowstr, lownum, highstr, highnum ):
            str += hfmt % ('Param', 'Best-Fit', 'Lower Bound', 'Upper Bound')
            str += hfmt % ('-'*5, '-'*8, '-'*11, '-'*11)

            for name, val, lower, upper in izip(self.parnames, self.parvals,
                                                self.parmins, self.parmaxes):

                str += '\n   %-12s %12g ' % (name, val)
                if is_iterable( lower ):
                    str += ' '
                    str += list_to_open_interval( lower )
                elif (lower is None):
                    str += lowstr % '-----'
                else:
                    str += lownum % lower
                if is_iterable( upper ):
                    str += '  '
                    str += list_to_open_interval( upper )
                elif (upper is None):
                    str += highstr % '-----'
                else:
                    str += highnum % upper

            return str

        low = map( is_iterable, self.parmins )
        high = map( is_iterable, self.parmaxes )
        in_low = is_in( True, low )
        in_high = is_in( True, high )
        mymethod = self.methodname == 'confidence'

        lowstr = '%12s '
        lownum = '%12g '
        highstr = '%12s'
        highnum = '%12g'

        if True == in_low and True == in_high and mymethod:
            hfmt = '\n   %-12s %12s %29s %29s'
            lowstr = '%29s '
            lownum = '%29g '
            highstr = '%30s'
            highnum = '%30g'
        elif True == in_low and False == in_high and mymethod:
            hfmt = '\n   %-12s %12s %29s %12s'
            lowstr = '%29s '
            lownum = '%29g '
            highstr = '%13s'
            highnum = '%13g'
        elif False == in_low and True == in_high and mymethod:
            hfmt = '\n   %-12s %12s %12s %29s'
            highstr = '%29s'
            highnum = '%29g'            
        else:
            hfmt = '\n   %-12s %12s %12s %12s'        

        return myformat( hfmt, s, lowstr, lownum, highstr, highnum )