Ejemplo n.º 1
0
    def __init__(self, fit, results, parlist = []):
        if (parlist == []):
            parlist = [p for p in fit.model.pars if not p.frozen]

        from sherpa.estmethods import est_success, est_hardmin, est_hardmax, est_hardminmax
        
        warning_hmin      = "hard minimum hit for parameter "
        warning_hmax      = "hard maximum hit for parameter "
        self.datasets     = None # To be set by calling function
        self.methodname   = type(fit.estmethod).__name__.lower()
        self.iterfitname  = fit._iterfit.itermethod_opts['name']
        self.fitname      = type(fit.method).__name__.lower()
        self.statname     = type(fit.stat).__name__.lower()
        self.sigma        = fit.estmethod.sigma
        self.percent      = erf(self.sigma / sqrt(2.0)) * 100.0
        self.parnames     = tuple(p.fullname for p in parlist if not p.frozen)
        self.parvals      = tuple(p.val for p in parlist if not p.frozen)
        self.parmins      = ()
        self.parmaxes     = ()
        self.nfits        = 0
        success           = True
        for i in range(len(parlist)):
            if (results[2][i] != est_success):
                success = False
            if (results[2][i] == est_hardmin or
                results[2][i] == est_hardminmax):
                self.parmins  = self.parmins + (None,)
                warning(warning_hmin + self.parnames[i])
            else:
                self.parmins  = self.parmins + (results[0][i],)

            if (results[2][i] == est_hardmax or
                results[2][i] == est_hardminmax):
                self.parmaxes  = self.parmaxes + (None,)
                warning(warning_hmax + self.parnames[i])
            else:
                self.parmaxes  = self.parmaxes + (results[1][i],)

        self.nfits = results[3]
        self.extra_output = results[4]

        NoNewAttributesAfterInit.__init__(self)
Ejemplo n.º 2
0
    def _region_init(self, fit, par0, par1):

        self.stat = fit.calc_stat()
        self.xlabel = par0.fullname
        self.ylabel = par1.fullname
        self.parval0 = par0.val
        self.parval1 = par1.val

        if self.levels is None:
            stat = self.stat
            if self.sigma is None or numpy.isscalar(self.sigma):
                raise ConfidenceErr('needlist', 'sigma bounds')
            thelevels = numpy.zeros(len(self.sigma), SherpaFloat)
            for i in range(len(self.sigma)):
                thelevels[i] = stat - (2. * numpy.log(1. - erf(
                    self.sigma[i]/numpy.sqrt(2.))))
            self.levels = thelevels

        if self.min is None or self.max is None:
            oldestmethod = fit.estmethod
            fit.estmethod = Covariance()

            r = fit.est_errors()
            fit.estmethod = oldestmethod

            index0 = list(r.parnames).index(par0.fullname)
            index1 = list(r.parnames).index(par1.fullname)

            if self.min is None:
                self.min = numpy.array([par0.min, par1.min])
                min0 = r.parmins[index0]
                min1 = r.parmins[index1]

                if min0 is not None and not numpy.isnan(min0):
                    self.min[0] = par0.val + min0

                if min1 is not None and not numpy.isnan(min1):
                    self.min[1] = par1.val + min1

            if self.max is None:
                self.max = numpy.array([par0.max, par1.max])
                max0 = r.parmaxes[index0]
                max1 = r.parmaxes[index1]

                if max0 is not None and not numpy.isnan(max0):
                    self.max[0] = par0.val + max0

                if max1 is not None and not numpy.isnan(max1):
                    self.max[1] = par1.val + max1

            # check user limits for errors
            if( numpy.isscalar( self.min ) or
                numpy.isscalar( self.max ) ):
                raise ConfidenceErr('badarg','Parameter limits', 'a list')

            for i in [0,1]:
                v = (self.max[i] + self.min[i]) / 2.
                dv = numpy.fabs(v - self.min[i])
                self.min[i] = v - self.fac * dv
                self.max[i] = v + self.fac * dv

        hmin = numpy.array([ par0.min, par1.min ])
        hmax = numpy.array([ par0.max, par1.max ])

        for i in [0,1]:
            # check user limits for errors
            if( numpy.isscalar( self.min ) or
                numpy.isscalar( self.max ) ):
                raise ConfidenceErr('badarg','Parameter limits', 'a list')

            if self.min[i] >= self.max[i]:
                raise ConfidenceErr('badlimits')

            if numpy.isscalar( self.nloop ) or self.nloop[i] <= 1:
                raise ConfidenceErr('badarg', 'Nloop parameter','a list with' +
                                      ' elements > 1')

            if self.min[i] < hmin[i]:
                self.min[i] = hmin[i]
            if self.max[i] > hmax[i]:
                self.max[i] = hmax[i]


        if self.delv is None:
            self.x0 = numpy.linspace(self.min[0],self.max[0],self.nloop[0])
            self.x1 = numpy.linspace(self.min[1],self.max[1],self.nloop[1])

        else:
            eps = numpy.finfo(numpy.float32).eps
            self.x0 = numpy.arange(self.min[0],self.max[0]+self.delv[0]-eps,
                                   self.delv[0])
            self.x1 = numpy.arange(self.min[1],self.max[1]+self.delv[1]-eps,
                                   self.delv[1])

        #x = numpy.array([self.x0, self.x1])
        x = [self.x0, self.x1]

        self.x0, self.x1 = numpy.meshgrid(self.x0, self.x1)
        self.x0 = self.x0.ravel()
        self.x1 = self.x1.ravel()

        for i in [0,1]:
            if self.log[i]:
                if self.max[i] <= 0.0 or self.min[i] <= 0.0:
                    raise ConfidenceErr('badarg', 'Log scale',
                                        'on positive boundaries')
                self.max[i] = numpy.log10(self.max[i])
                self.min[i] = numpy.log10(self.min[i])
                x[i] = numpy.linspace(self.min[i],self.max[i],len(x[i]))

        x0, x1 = numpy.meshgrid(x[0], x[1])
        return numpy.array([x0.ravel(), x1.ravel()]).T