A python implementation of the cummin function in R
434964
def cummin(x):
    """"""
    for i in range(1, len(x)):
        if x[i-1] < x[i]:
            x[i] = x[i-1]
    return x
307344
def cumany(series):
    

    anys = series.expanding().apply(np.any).astype(bool)
    return anys
968974
def _K(self, R):
        """"""
        return self._ns * self._N / R / self._sin_alpha
1014623
def _parse_fc(self, f, natom, dim):
        

        ndim = np.prod(dim)
        fc = np.zeros((natom, natom * ndim, 3, 3), dtype='double', order='C')
        for k, l, i, j in np.ndindex((3, 3, natom, natom)):
            line = f.readline()
            for i_dim in range(ndim):
                line = f.readline()
                # fc[i, j * ndim + i_dim, k, l] = float(line.split()[3])
                fc[j, i * ndim + i_dim, l, k] = float(line.split()[3])
        return fc
24351
def obfn_cns(self):
        
        """

        return np.linalg.norm((self.Pcn(self.obfn_gvar()) - self.obfn_gvar()))
1161169
def y0astep():
    
    """

    global mp_b
    mp_b[:] = mp_inv_off_diag * np.sum((mp_S + mp_rho*(mp_DX+mp_U0)),
                                       axis=mp_axisM, keepdims=True)
539281
function bfrac(a, b, x, y) {
      var lambda;

      lambda = a - (a + b) * x;
      return brcomp(a, b, x, y) + Math.log(contFrac(
         function(i) { // betas from DiDonato
            var n;

            n = i - 1;
            return i === 0 ? 0
                           : n + n * (b - n) * x / (a + 2 * n - 1) +
                             (a + n) / (a + 2 * n + 1) *
                                (lambda + 1 + n * (1 + y));
         },
         function(i) { // alphas from DiDonato
            var n;

            n = i - 1;
            return i === 1 ? 1
                           : (a + n - 1) * (a + b + n - 1) /
                             (a + 2 * n - 1) / (a + 2 * n - 1) *
                             n * (b - n) * x * x;
         }
      ));
   }
935018
def _nbinom_ztrunc_p(mu, k_agg):
        

        p_eq = lambda p, mu, k_agg: (k_agg * p) / (1 - (1 + p)**-k_agg) - mu

        # The upper bound needs to be large. p will increase with increasing mu
        # and decreasing k_agg
        p = optim.brentq(p_eq, 1e-10, 1e10, args=(mu, k_agg))
        return p
1037165
def cumprod(self, axis=0, *args, **kwargs):
        
        nv.validate_groupby_func('cumprod', args, kwargs,
                                 ['numeric_only', 'skipna'])
        if axis != 0:
            return self.apply(lambda x: x.cumprod(axis=axis, **kwargs))

        return self._cython_transform('cumprod', **kwargs)
831579
function(lst, probs) {
    var p = randf(0, 1.0);
    var cumprob = 0.0;
    for(var k=0,n=lst.length;k<n;k++) {
      cumprob += probs[k];
      if(p < cumprob) { return lst[k]; }
    }
  }
1320211
def _stieltjes_approx(dist, order, accuracy, normed, **kws):
    """"""
    kws["rule"] = kws.get("rule", "C")
    assert kws["rule"].upper() != "G"

    absisas, weights = chaospy.quad.generate_quadrature(
        accuracy, dist.range(), **kws)
    weights = weights*dist.pdf(absisas)

    poly = chaospy.poly.variable(len(dist))
    orth = [poly*0, poly**0]

    inner = numpy.sum(absisas*weights, -1)
    norms = [numpy.ones(len(dist)), numpy.ones(len(dist))]
    coeff1 = []
    coeff2 = []

    for _ in range(order):

        coeff1.append(inner/norms[-1])
        coeff2.append(norms[-1]/norms[-2])
        orth.append((poly-coeff1[-1])*orth[-1] - orth[-2]*coeff2[-1])

        raw_nodes = orth[-1](*absisas)**2*weights
        inner = numpy.sum(absisas*raw_nodes, -1)
        norms.append(numpy.sum(raw_nodes, -1))

        if normed:
            orth[-1] = orth[-1]/numpy.sqrt(norms[-1])

    coeff1.append(inner/norms[-1])
    coeff2.append(norms[-1]/norms[-2])
    coeff1 = numpy.transpose(coeff1)
    coeff2 = numpy.transpose(coeff2)
    norms = numpy.array(norms[1:]).T
    orth = orth[1:]
    return orth, norms, coeff1, coeff2
1028928
def cumsum(x, dim, exclusive=False):
  
  with tf.variable_scope("cumsum"):
    new_name = "tmp_dim_cumsum"
    new_dim = Dimension(new_name, dim.size)
    new_shape = x.shape.rename_dimension(dim.name, new_name)
    comparator = less if exclusive else less_equal
    m = cast(
        comparator(mtf_range(x.mesh, dim, dtype=tf.float32),
                   mtf_range(x.mesh, new_dim, dtype=tf.float32)), x.dtype)
    ret = einsum([x, m], output_shape=new_shape)
    return reshape(ret, x.shape)
1176765
def value2rgba(x:float, cmap:Callable=cm.RdYlGn, alpha_mult:float=1.0)->Tuple:
    ""
    c = cmap(x)
    rgb = (np.array(c[:-1]) * 255).astype(int)
    a = c[-1] * alpha_mult
    return tuple(rgb.tolist() + [a])
363199
def obfn_g(self, Y):
        
        """

        return self.obfn_g0(self.obfn_g0var()) + \
            self.obfn_g1(self.obfn_g1var())
946366
def _exponential_kamb(cos_dist, sigma=3):
    """"""
    n = float(cos_dist.size)
    f = 2 * (1.0 + n / sigma**2)
    count = np.exp(f * (cos_dist - 1))
    units = np.sqrt(n * (f/2.0 - 1) / f**2)
    return count, units
863717
def computeCovarianceMatrixPlink(plink_path,out_dir,bfile,cfile,sim_type='RRM'):
    

    print("Using plink to create covariance matrix")
    cmd = '%s --bfile %s '%(plink_path,bfile)

    if sim_type=='RRM':
        # using variance standardization
        cmd += '--make-rel square '
    else:
        raise Exception('sim_type %s is not known'%sim_type)

    cmd+= '--out %s'%(os.path.join(out_dir,'plink'))

    subprocess.call(cmd,shell=True)

    # move file to specified file
    if sim_type=='RRM':
        old_fn = os.path.join(out_dir, 'plink.rel')
        os.rename(old_fn,cfile+'.cov')

        old_fn = os.path.join(out_dir, 'plink.rel.id')
        os.rename(old_fn,cfile+'.cov.id')

    if sim_type=='IBS':
        old_fn = os.path.join(out_dir, 'plink.mibs')
        os.rename(old_fn,cfile+'.cov')

        old_fn = os.path.join(out_dir, 'plink.mibs.id')
        os.rename(old_fn,cfile+'.cov.id')
371793
def drawFrom(self, cumsum, r):
        
        a = cumsum.rsplit()
        if len(a)>1:
            b = eval(a[0])[int(a[1])]
        else:
            b = eval(a[0])
            
        return np.nonzero(b>=r)[0][0]