Randomly samples from the Dentate Gyrus dataset.

    Arguments
    ---------
    n_obs: `int`
        Size of the sampled dataset

    Returns
    -------
    Returns `adata` object
770523
def toy_data(n_obs):
    

    """Random samples from Dentate Gyrus.
    """
    adata = dentategyrus()
    indices = np.random.choice(adata.n_obs, n_obs)
    adata = adata[indices]
    adata.obs_names = np.array(range(adata.n_obs), dtype='str')
    adata.var_names_make_unique()
    return adata
314585
def mean_cl_boot(series, n_samples=1000, confidence_interval=0.95,
                 random_state=None):
    
    return bootstrap_statistics(series, np.mean,
                                n_samples=n_samples,
                                confidence_interval=confidence_interval,
                                random_state=random_state)
1362961
def sample(self, n):
        
        rg = self._ctx._jvm.org.apache.commons.math3.random.JDKRandomGenerator()
        return _java2py(self._ctx, self._jmodel.sample(n, rg))
394095
def randsample(vec, nr_samples, with_replacement = False):
    
    if not with_replacement:
        return np.random.permutation(vec)[0:nr_samples]
    else:
        return np.asarray(vec)[np.random.randint(0, len(vec), nr_samples)]
1061107
def dt_comp(self, sampled_topics):

        

        samples = sampled_topics.shape[0]
        dt = np.zeros((self.D, self.K, samples))

        for s in range(samples):            
                dt[:, :, s] = \
                    samplers_lda.dt_comp(self.docid, sampled_topics[s, :],
                                         self.N, self.K, self.D, self.alpha)

        return dt
993858
def random_sample(col, n=5, filters=None):
    
    pipeline = list()
    if filters is not None:
        pipeline.append({"$match": filters})
    pipeline.append({"$sample": {"size": n}})
    return list(col.aggregate(pipeline))
1035077
def _sample(self, position, stepsize):
        

        # Re-sampling momentum
        momentum = np.random.normal(0, 1, len(position))

        # Initializations
        depth = 0
        position_backward, position_forward = position, position
        momentum_backward, momentum_forward = momentum, momentum
        candidate_set_size = accept_set_bool = 1
        _, log_pdf = self.grad_log_pdf(position, self.model).get_gradient_log_pdf()

        # Resample slice variable `u`
        slice_var = np.random.uniform(0, np.exp(log_pdf - 0.5 * np.dot(momentum, momentum)))

        while accept_set_bool == 1:
            direction = np.random.choice([-1, 1], p=[0.5, 0.5])
            if direction == -1:
                # Build a tree in backward direction
                (position_backward, momentum_backward, _, _, position_bar,
                 candidate_set_size2, accept_set_bool2) = self._build_tree(position_backward, momentum_backward,
                                                                           slice_var, direction, depth, stepsize)
            else:
                # Build tree in forward direction
                (_, _, position_forward, momentum_forward, position_bar,
                 candidate_set_size2, accept_set_bool2) = self._build_tree(position_forward, momentum_forward,
                                                                           slice_var, direction, depth, stepsize)
            if accept_set_bool2 == 1:
                if np.random.rand() < candidate_set_size2 / candidate_set_size:
                    position = position_bar.copy()

            accept_set_bool, candidate_set_size = self._update_acceptance_criteria(position_forward, position_backward,
                                                                                   momentum_forward, momentum_backward,
                                                                                   accept_set_bool2, candidate_set_size,
                                                                                   candidate_set_size2)
            depth += 1

        return position
296299
def _sample_aAt(self,n):
        """"""
        #Sample frequency along largest eigenvalue using ARS
        dO1s=\
            bovy_ars.bovy_ars([0.,0.],[True,False],
                              [self._meandO-numpy.sqrt(self._sortedSigOEig[2]),
                               self._meandO+numpy.sqrt(self._sortedSigOEig[2])],
                              _h_ars,_hp_ars,nsamples=n,
                              hxparams=(self._meandO,self._sortedSigOEig[2]),
                              maxn=100)
        dO1s= numpy.array(dO1s)*self._sigMeanSign
        dO2s= numpy.random.normal(size=n)*numpy.sqrt(self._sortedSigOEig[1])
        dO3s= numpy.random.normal(size=n)*numpy.sqrt(self._sortedSigOEig[0])
        #Rotate into dOs in R,phi,z coordinates
        dO= numpy.vstack((dO3s,dO2s,dO1s))
        dO= numpy.dot(self._sigomatrixEig[1][:,self._sigomatrixEigsortIndx],
                      dO)
        Om= dO+numpy.tile(self._progenitor_Omega.T,(n,1)).T
        #Also generate angles
        da= numpy.random.normal(size=(3,n))*self._sigangle
        #And a random time
        dt= self.sample_t(n)
        #Integrate the orbits relative to the progenitor
        da+= dO*numpy.tile(dt,(3,1))
        angle= da+numpy.tile(self._progenitor_angle.T,(n,1)).T
        return (Om,angle,dt)
317279
def getNextSample(self, V):
        

        positions = range(0, len(self.wmg))
        randPoss = random.sample(positions, self.shuffleSize)
        flipSet = copy.deepcopy(randPoss)
        randPoss.sort()
        W = copy.deepcopy(V)
        for j in range(0, self.shuffleSize):
            W[randPoss[j]] = V[flipSet[j]]

        # Check whether we should change to the new ranking.
        prMW = 1.0
        prMV = 1.0
        acceptanceRatio = self.calcAcceptanceRatio(V, W)
        prob = min(1.0,(prMW/prMV)*acceptanceRatio)
        if random.random() <= prob:
            V = W
        return V
1120794
def mcmc_emcee(self, n_walkers, n_run, n_burn, mean_start, sigma_start):
        
        sampler = emcee.EnsembleSampler(n_walkers, self.cosmoParam.numParam, self.chain.likelihood)
        p0 = emcee.utils.sample_ball(mean_start, sigma_start, n_walkers)
        new_pos, _, _, _ = sampler.run_mcmc(p0, n_burn)
        sampler.reset()
        store = InMemoryStorageUtil()
        for pos, prob, _, _ in sampler.sample(new_pos, iterations=n_run):
            store.persistSamplingValues(pos, prob, None)
        return store.samples
167945
def sample_from_likelihood(self, n_timesteps=10):
        

        self.latent_state_sequences = lmap(
            lambda A: ltake(
                n_timesteps,
                iterate(
                    lambda s: pd.Series(A @ s.values, index=s.index), self.s0
                ),
            ),
            self.transition_matrix_collection,
        )

        self.observed_state_sequences = [
            [self.sample_observed_state(s) for s in latent_state_sequence]
            for latent_state_sequence in self.latent_state_sequences
        ]
1330755
def _next_sample_index(self):
        
        return self.rng.choice(self.n_streams,
                               p=(self.stream_weights_ /
                                  self.weight_norm_))
38139
def sample(self, N=1):
        
        if not self.filt:
            self.forward()
        paths = np.empty((len(self.filt), N), np.int)
        paths[-1, :] = rs.multinomial(self.filt[-1], M=N)
        log_trans = np.log(self.hmm.trans_mat)
        for t, f in reversed(list(enumerate(self.filt[:-1]))):
            for n in range(N):
                probs = rs.exp_and_normalise(log_trans[:, paths[t + 1, n]] + np.log(f))
                paths[t, n] = rs.multinomial_once(probs)
        return paths
323352
def sample_labels(self, n):
        
        if n >= len(self):
            return self.labels
        sample = random.sample(self.labels, n)
        return set(sample)
975334
def samples(self, nsamples, rstate=None):
        

        if rstate is None:
            rstate = np.random

        xs = np.array([self.sample(rstate=rstate) for i in range(nsamples)])

        return xs
624290
def sample_posterior(x,post,nsamples=1):
    
    cdf = post.cumsum()
    cdf /= cdf.max()
    u = rand.random(size=nsamples)
    inds = np.digitize(u,cdf)
    return x[inds]
737744
def _get_samples(n, sim, inc_warmup=True):
    # NOTE: this is in stanfit-class.R in RStan (rather than misc.R)
    
    return pystan._misc.get_samples(n, sim, inc_warmup)