Returns the cR statistic for the variogram fit (see [1]).
507296
def calc_cR(Q2, sigma):
    """"""
    return Q2 * np.exp(np.sum(np.log(sigma**2))/sigma.shape[0])
693425
def result(self):
        
        # TODO: how about xcurrent?
        return self.best.get() + (
            self.countevals, self.countiter, self.gp.pheno(self.mean),
            self.gp.scales * self.sigma * self.sigma_vec * self.dC**0.5)
979954
def _get_c_valid_arr(self, x):
        
        orig_shape = x.shape
        x = np.ascontiguousarray(x.reshape(orig_shape[0], -1).T)
        return orig_shape, x
887326
def get_rmetric( self, mode_inv = 'svd', return_svd = False ):
        
        if self.H is None:
            self.H, self.G, self.Hvv, self.Hsval = riemann_metric(self.Y, self.L, self.mdimG, invert_h = True, mode_inv = mode_inv)
        if self.G is None:
            self.G, self.Hvv, self.Hsvals,  self.Gsvals = compute_G_from_H( self.H, mode_inv = self.mode_inv )
        if mode_inv is 'svd' and return_svd:
            return self.G, self.Hvv, self.Hsvals, self.Gsvals
        else:
            return self.G
1316296
def _get_covariance(self, X):
        
        result = pd.DataFrame(index=range(len(X)))
        column_names = self.get_column_names(X)
        for column_name in column_names:
            column = self.get_column(X, column_name)
            distrib = self.distribs[column_name]

            # get original distrib's cdf of the column
            cdf = distrib.cumulative_distribution(column)

            if distrib.constant_value is not None:
                # This is to avoid np.inf in the case the column is constant.
                cdf = np.ones(column.shape) - EPSILON

            # get inverse cdf using standard normal
            result = self.set_column(result, column_name, stats.norm.ppf(cdf))

        # remove any rows that have infinite values
        result = result[(result != np.inf).all(axis=1)]
        return pd.DataFrame(data=result).cov().values
723250
def fit(self, x, y, *args, **kwargs):
        

        points = self._dimensionality_check(x)

        # if condition required to address backward compatibility
        if self.method in threed_krige:
            self.model = krige_methods[self.method](
                val=y,
                variogram_model=self.variogram_model,
                nlags=self.nlags,
                weight=self.weight,
                verbose=self.verbose,
                **points
            )
        else:
            self.model = krige_methods[self.method](
                z=y,
                variogram_model=self.variogram_model,
                nlags=self.nlags,
                weight=self.weight,
                verbose=self.verbose,
                **points
            )
1115762
def precision(self):
        
        if self._precision is None:
            cov = np.atleast_3d(self.covariance)
            self._precision = np.zeros(cov.shape)  # if one covariance per dimension
            for p in range(cov.shape[-1]):
                self._precision[:, :, p] = pdinv(cov[:, :, p])[0]
        return self._precision
795457
def rdirichlet(theta, size=1):
    
    gammas = np.vstack([rgamma(theta, 1) for i in xrange(size)])
    if size > 1 and np.size(theta) > 1:
        return (gammas.T / gammas.sum(1))[:-1].T
    elif np.size(theta) > 1:
        return (gammas[0] / gammas[0].sum())[:-1]
    else:
        return 1.
167683
def fit(self):
        
        # solve for estimator of B
        n,p          = np.shape(self._X)
        self._df     = float(n - p)
        self._Cx     = np.linalg.pinv(np.dot(self._X.T,self._X))
        self._Bhat   = np.dot(np.dot(self._Cx, self._X.T), self._A)
        self._Y_rec  = self._compute_prediction(self._X)
460266
def __Calc_HSL_to_RGB_Components(var_q, var_p, C):
    
    if C < 0:
        C += 1.0
    if C > 1:
        C -= 1.0

    # Computing C of vector (Color R, Color G, Color B)
    if C < (1.0 / 6.0):
        return var_p + ((var_q - var_p) * 6.0 * C)
    elif (1.0 / 6.0) <= C < 0.5:
        return var_q
    elif 0.5 <= C < (2.0 / 3.0):
        return var_p + ((var_q - var_p) * 6.0 * ((2.0 / 3.0) - C))
    else:
        return var_p
388003
def calculate(cls, byte_arr, crc=0):
        """"""
        for byte in byte_iter(byte_arr):
            # Taken verbatim from FIT SDK docs
            tmp = cls.CRC_TABLE[crc & 0xF]
            crc = (crc >> 4) & 0x0FFF
            crc = crc ^ tmp ^ cls.CRC_TABLE[byte & 0xF]

            tmp = cls.CRC_TABLE[crc & 0xF]
            crc = (crc >> 4) & 0x0FFF
            crc = crc ^ tmp ^ cls.CRC_TABLE[(byte >> 4) & 0xF]
        return crc
184329
def crps(self):
        
        return np.sum(self.errors["F_2"].values - self.errors["F_O"].values * 2.0 + self.errors["O_2"].values) / \
            (self.thresholds.size * self.num_forecasts)
525808
def _calc_var_theta(self):
        """"""
        if self.decaying_prior:
            n_sampled = np.clip(self.alpha_ + self.beta_, 1, np.inf)
            prior_weight = 1/n_sampled
            alpha = self.alpha_ + prior_weight * self.alpha_0
            beta = self.beta_ + prior_weight * self.beta_0
        else:
            alpha = self.alpha_ + self.alpha_0
            beta = self.beta_ + self.beta_0
        # Variance of Beta-distributed rv
        self.var_theta_ = ( alpha * beta /
                            ((alpha + beta)**2 * (alpha + beta + 1)) )
1249967
def power_variogram_model(m, d):
    """"""
    scale = float(m[0])
    exponent = float(m[1])
    nugget = float(m[2])
    return scale * d**exponent + nugget
274331
def get_mmr_constants():
    '''
    
    '''

    Cnt = {
        'ISOTOPE':'F18',
        'DCYCRR':DCYCRR,
        'ALPHA':ALPHA,
        'NRNG':NRNG,
        'NSRNG':NSRNG,
        'NCRS':NCRS,
        'NCRSR':NCRSR,
        'NBCKT':224,
        'NSANGLES':A,
        'NSBINS':W,
        'Naw':-1,   # number of total active bins per 2D sino
        'NSN11': NSN11, # number of sinos in span-11
        'NSN1': NSN1, # number of sinos in span-1
        'NSN64': NSN64, # number of sinos in span-1 with no MRD limit
        'MRD': MRD, # maximum ring difference RD
        'SPN':SPAN, # span-1 (1), span-11 (11), ssrb (0)
        'TFOV2':TFOV2, # squared radius of TFOV

        'RNG_STRT':RNG_STRT, # limit axial extension by defining start and end ring
        'RNG_END' :RNG_END,  # this feature only works with span-1 processing (Cnt['SPN']=1)

        'SS_IMZ':SS_IMZ, #Scatter mu-map iamge size 
        'SS_IMY':SS_IMY,
        'SS_IMX':SS_IMX,
        'SS_VXZ':SS_VXZ,
        'SS_VXY':SS_VXY,
        'IS_VXZ':IS_VXZ,
        'SSE_IMZ':SSE_IMZ, #Scatter emission image size
        'SSE_IMY':SSE_IMY,
        'SSE_IMX':SSE_IMX,
        'SSE_VXZ':SSE_VXZ,
        'SSE_VXY':SSE_VXY,
        'SZ_IMZ':SZ_IMZ, #GPU optimised image size
        'SZ_IMY':SZ_IMY,
        'SZ_IMX':SZ_IMX,
        'SZ_VOXZ':SZ_VOXZ,
        'SZ_VOXY':SZ_VOXY,
        'SZ_VOXZi':SZ_VOXZi,
        'SO_IMZ':SO_IMZ, #Original image size (from Siemens)
        'SO_IMY':SO_IMY,
        'SO_IMX':SO_IMX,
        'SO_VXZ':SO_VXZ,
        'SO_VXY':SO_VXY,
        'SO_VXX':SO_VXX,
        'NSEG0':SEG0,
        'RE':RE, #effective ring radius
        'R':R,
        'SEG':seg,
        'MNRD':minrd,
        'MXRD':maxrd,
        'SCTRNG':sct_irng,
        'TGAP':TGAP,
        'OFFGAP':OFFGAP,
        'AXR':AXR,
        'R02':R02, #squared electron radius
        'LLD':LLD, #lower energy threashold
        'E511':E511,
        'ER':ER, #energy resolution
        'COSUPSMX':COSUPSMX, #cosine of max allowed scatter angle
        'NCOS':NCOS, #number of cos samples for LUT
        'COSSTP':COSSTP, #cosine step
        'ICOSSTP':ICOSSTP, #inverse of cosine step
        'ETHRLD':ETHRLD, #intensity emission image threshold (used in scatter modelling)
        'CLGHT':CLGHT, #speed of light [cm/s]
        'CWND':CWND,    #coincidence time window [ps]
        'TOFBINN':TOFBINN, #number of TOF bins
        'TOFBINS':TOFBINS,   #TOF bin width [ps]
        'TOFBIND':TOFBIND,
        'ITOFBIND':ITOFBIND,
        # affine and image size for the reconstructed image, assuming the centre of voxels in mm
        'AFFINE':np.array([ [-10*SO_VXX, 0., 0., 5.*SO_IMX*SO_VXX ], #+5.*SO_VXX
                            [0., 10*SO_VXY, 0., -5.*SO_IMY*SO_VXY ], #+5.*SO_VXY
                            [0., 0., 10*SO_VXZ, -5.*SO_IMZ*SO_VXZ ], #-5.*SO_VXZ
                            [0., 0., 0., 1.]]),
        'IMSIZE':np.array([SO_IMZ, SO_IMY, SO_IMX]),


        'BTP':0, #1:non parametric bootstrap, 2: parametric bootstrap (recommended)
        'BTPRT':1.0, # Ratio of bootstrapped/original events (enables downsampling)

        'VERBOSE':False,

        'SCTSCLEM':SCTSCLEM,
        'SCTSCLMU':SCTSCLMU,
    }

    # get the setup for GPU and third party apps
    Cnt = get_setup(Cnt=Cnt)

    return Cnt
649776
function( hue_c, variance ){
            if( is.Hue(hue_c) ){
                return TColor.newHSVA(
                    hue_c.getHue(),
                    pickRandom(this.saturationConstraint).pickRandom(),
                    pickRandom(this.brightnessConstraint).pickRandom(),
                    pickRandom(this.alphaConstraint).pickRandom()
                );
            }
            //must be a TColor
            var c = hue_c, h, s, b, a;
            if( c ){
                if( c.isBlack() ){
                    return TColor.newHSVA(c.hue(), 0, this.black.pickRandom(), c.alpha() );
                } else if( c.isWhite() ){
                    return TColor.newHSVA(c.hue(), 0, this.white.pickRandom(), c.alpha() );
                }
                if( c.isGrey() ){
                    return TColor.newHSVA(
                        c.hue(),
                        0,
                        MathUtils.flipCoin() ? this.black.pickRandom() : this.white.pickRandom(),
                        c.alpha()
                    );
                }
                h = c.hue() + variance * MathUtils.normalizedRandom();
                a = c.alpha();
            } else {
                h = pickRandom(this.hueConstraint).pickRandom();
                a = pickRandom(this.alphaConstraint).pickRandom();
            }
            s = pickRandom(this.saturationConstraint).pickRandom();
            b = pickRandom(this.brightnessConstraint).pickRandom();
            return TColor.newHSVA(h,s,b,a);
        }
515883
def _get_SRF_sigma(self, imt_per):
        
        if imt_per < 0.6:
            srf = 0.8
        elif 0.6 <= imt_per < 1:
            srf = self._interp_function(0.7, 0.8, 1, 0.6, imt_per)
        elif 1 <= imt_per <= 10:
            srf = self._interp_function(0.6, 0.7, 10, 1, imt_per)
        else:
            srf = 1

        return srf