Пример #1
0
def gauss_cdf ( x , mu = 0.0 , sigma = 1.0 ) :
    """Standard gaussian CDF:
    
    >>> x,mu, sigma = ....
    >>> cdf = gauss_cdf ( x  , mu , sigma )
    """
    y =  VE ( x ) 
    return _gauss_cdf_ ( y if 0 < y.cov2() else y.value () , mu , sigma )
Пример #2
0
    def __call__ ( self , x , y , cxy = 0 ) :
        """Evaluate the function 
        >>> func2 = lambda x,y : x*x + y*y
        >>> eval2 = Eval2VE ( func2 )
        >>> x = VE(1,0.1**2)
        >>> y = VE(2,0.1**2)
        >>> print eval2(x,y)    ## treat x,y as uncorrelated 
        >>> print eval2(x,y, 0) ## ditto 
        >>> print eval2(x,y,+1) ## treat x,y as 100% correlated 
        >>> print eval2(x,y,-1) ## treat x,y as 100% anti-correlated
        """
        assert isinstance ( cxy , num_types ) and \
               ( abs ( cxy ) <= 1 or isequal ( abs ( cxy ) , 1 ) ) , \
               'Invalid correlation coefficient %s' % cxy 
        
        x   = VE ( x ) 
        y   = VE ( y )
        
        xv  = x.value()
        yv  = y.value()
        
        val = self.func ( xv , yv )

        xc2 = x.cov2()
        yc2 = x.cov2()
        
        x_plain = xc2 <= 0 or iszero ( xc2 )
        y_plain = yc2 <= 0 or iszero ( yc2 )
        
        #
        if x_plain and y_plain : return VE ( val , 0 )
        
        #
        ## here we need to calculate the uncertainties
        # 
        dx   = self.partial[0] ( xv , yv ) if not x_plain else 0 
        dy   = self.partial[1] ( xv , yv ) if not y_plain else 0 
        #
        
        cov2 = dx * dx * xc2 + dy * dy * yc2
        
        if cxy and xc2 and yc2 :
            cov2 += 2 * cxy * dx * dy * math.sqrt ( xc2 * yc2 ) 
            
        return VE ( val , cov2 )
Пример #3
0
    def __call__(self, x, y, cxy=0):
        """Evaluate the function 
        >>> func2 = lambda x,y : x*x + y*y
        >>> eval2 = Eval2VE ( func2 )
        >>> x = VE(1,0.1**2)
        >>> y = VE(2,0.1**2)
        >>> print eval2(x,y)    ## treat x,y as uncorrelated 
        >>> print eval2(x,y, 0) ## ditto 
        >>> print eval2(x,y,+1) ## treat x,y as 100% correlated 
        >>> print eval2(x,y,-1) ## treat x,y as 100% anti-correlated
        """
        ## evaluate the function
        val = self._value_(x, y)
        #
        x = VE(x)
        y = VE(y)
        #
        x_plain = x.cov2() <= 0 or iszero(x.cov2())
        y_plain = y.cov2() <= 0 or iszero(y.cov2())
        #
        if x_plain and y_plain: return VE(val, 0)
        #
        ## here we need to calculate the uncertainties
        #
        cov2 = 0.0
        #
        fx = self.dFdX(x, y.value()) if not x_plain else 0
        fy = self.dFdY(x.value(), y) if not y_plain else 0
        #
        if not x_plain: cov2 += fx * fx * x.cov2()
        if not y_plain: cov2 += fy * fy * y.cov2()
        #
        if not x_plain and not y_plain:
            ## adjust the correlation coefficient:
            cxy = min(max(-1, cxy), 1)
            if not iszero(cxy):
                cov2 += 2 * cxy * fx * fy * x.error() * y.error()

        return VE(val, cov2)
Пример #4
0
def pretty_ve ( value , width = 8 , precision = 6 , parentheses = True ) :
    """Nice printout of the ValueWithError object  ( string + exponent)
    - return nice stirng and the separate exponent 
    >>> s , n = pretty_ve ( number ) 
    """
    from ostap.math.ve          import VE
    value =  VE ( value )
    
    fmt , fmtv , fmte , n = fmt_pretty_ve ( value , width , precision , parentheses )
    
    v =           value.value ()   
    e = max ( 0 , value.error () ) 
    
    return fmt % ( v / 10**n , e / 10**n ) , n 
Пример #5
0
 def dFdY(self, x, y):
     """Get a partial derivatives d(func)/d(Y)"""
     y = VE(y)
     return self._partial_(self._dFdY, x, y.value(), y.cov2())
Пример #6
0
 def dFdX(self, x, y):
     """Get a partial derivatives d(func)/d(X)"""
     x = VE(x)
     return self._partial_(self._dFdX, x.value(), y, x.cov2())