numpy.random.exponential - python examples

Here are the examples of the python api numpy.random.exponential taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

56 Examples 7

3 View Complete Implementation : distribution.py
Copyright MIT License
Author : acsicuib
    def next(self):
        if not self.started:
            self.started = True
            return self.start
        else:
            return int(np.random.exponential(self.lambd, size=1)[0])

3 View Complete Implementation : gillespie_base.py
Copyright Apache License 2.0
Author : amzn
    def _draw_next_event(self, state: np.ndarray) -> Tuple[float, float]:
        """Draws which event of infection or recovery happens next"""
        # Compute current rates and the sum thereof
        rates = self._get_current_rates(state)
        sum_of_rates = rates.sum()

        # draw timestep from exponential distribution
        dt = np.random.exponential(1.0 / sum_of_rates)

        # draw occurring event according to current rates
        event = np.random.choice(np.asarray([i for i in range(len(self.initial_state))], dtype=int),
                                 p=rates / sum_of_rates)

        return event, dt

3 View Complete Implementation : test_matfuncs.py
Copyright MIT License
Author : alvarob96
    @pytest.mark.slow
    @pytest.mark.skip(reason='this test is deliberately slow')
    def test_medium_matrix(self):
        # profile this to see the speed difference
        n = 1000
        A = np.random.exponential(size=(n, n))
        E = np.random.exponential(size=(n, n))
        sps_expm, sps_frechet = expm_frechet(
                A, E, method='SPS')
        blockEnlarge_expm, blockEnlarge_frechet = expm_frechet(
                A, E, method='blockEnlarge')
        astert_allclose(sps_expm, blockEnlarge_expm)
        astert_allclose(sps_frechet, blockEnlarge_frechet)

3 View Complete Implementation : test_imputer_iterators.py
Copyright Apache License 2.0
Author : awslabs
def test_iter_decoder_df():
    # draw skewed brands
    brands = [{feature_col: brand} for brand in
              list(map(lambda e: str(int(e)), np.random.exponential(scale=1, size=1000)))]

    brand_df = pd.DataFrame(brands)
    it = ImputerIterDf(brand_df,
                       data_columns=[SequentialEncoder(feature_col, max_tokens=10, seq_len=2)],
                       label_columns=[CategoricalEncoder(feature_col, max_tokens=100)],
                       batch_size=2)
    decoded = it.decode(next(it).label)
    np.testing.astert_array_equal(decoded[0], brand_df[feature_col].head(it.batch_size).values)

3 View Complete Implementation : test_imputer_iterators.py
Copyright Apache License 2.0
Author : awslabs
def test_iter_padding_offset():
    col = 'brand'
    df = pd.DataFrame(
        [{col: brand} for brand in
         list(map(lambda e: str(int(e)), np.random.exponential(scale=1, size=36)))]
    )
    df_train = df.sample(frac=0.5)
    it = ImputerIterDf(
        df_train,
        data_columns=[BowEncoder(col)],
        label_columns=[CategoricalEncoder(col, max_tokens=5)],
        batch_size=32
    )
    astert it.start_padding_idx == df_train.shape[0]

3 View Complete Implementation : brownian_meander.py
Copyright MIT License
Author : crflynn
    def _sample_brownian_meander_at(self, times, b=None):
        """Generate a Brownian meander realization.

        Williams, 1970, or Imhof, 1984.
        """
        if b is None:
            b = np.sqrt(2 * times[-1] * np.random.exponential())
        else:
            self._check_nonnegative_number(b, "Right endpoint")

        bridge_1 = self._sample_brownian_bridge_at(times)
        bridge_2 = self._sample_brownian_bridge_at(times)
        bridge_3 = self._sample_brownian_bridge_at(times)

        return np.sqrt(
            (b * times / times[-1] + bridge_1) ** 2 +
            bridge_2 ** 2 + bridge_3 ** 2
        )

3 View Complete Implementation : causal_mechanisms.py
Copyright MIT License
Author : Diviyan-Kalainathan
    def __init__(self, ncauses, points, noise_function, d=4, noise_coeff=.4):
        """Init the mechanism."""
        super(SigmoidAM_Mechanism, self).__init__()
        self.n_causes = ncauses
        self.points = points

        self.a = np.random.exponential(1/4) + 1
        ber = bernoulli.rvs(0.5)
        self.b = ber * np.random.uniform(-2, -0.5) + (1-ber)*np.random.uniform(0.5, 2)
        self.c = np.random.uniform(-2, 2)
        self.noise = noise_coeff * noise_function(points)

3 View Complete Implementation : causal_mechanisms.py
Copyright MIT License
Author : Diviyan-Kalainathan
    def __init__(self, ncauses, points, noise_function, d=4, noise_coeff=.4):
        """Init the mechanism."""
        super(SigmoidMix_Mechanism, self).__init__()
        self.n_causes = ncauses
        self.points = points

        self.a = np.random.exponential(1/4) + 1
        ber = bernoulli.rvs(0.5)
        self.b = ber * np.random.uniform(-2, -0.5) + (1-ber)*np.random.uniform(0.5, 2)
        self.c = np.random.uniform(-2, 2)

        self.noise = noise_coeff * noise_function(points)

3 View Complete Implementation : test_matfuncs.py
Copyright Apache License 2.0
Author : dnanexus
    @decorators.slow
    @decorators.skipif(True, 'this test is deliberately slow')
    def test_medium_matrix(self):
        # profile this to see the speed difference
        n = 1000
        A = np.random.exponential(size=(n, n))
        E = np.random.exponential(size=(n, n))
        sps_expm, sps_frechet = expm_frechet(
                A, E, method='SPS')
        blockEnlarge_expm, blockEnlarge_frechet = expm_frechet(
                A, E, method='blockEnlarge')
        astert_allclose(sps_expm, blockEnlarge_expm)
        astert_allclose(sps_frechet, blockEnlarge_frechet)

3 View Complete Implementation : model.py
Copyright MIT License
Author : EliseJ
        def make_mock(self, param, var):
                '''
                Input:
                        param: variable to generate either exponential data or Normal data with variance = var
                '''
                if self.name == "exp":
                        b = 1/param[0]
                        return np.random.exponential(b,self.num)
                if self.name == "normal":
                        if isinstance(var,float):
                                sigm = np.diag(np.ones(len(param))*var)
                        elif len(var)==len(param):
                                sigm = np.diag(var)
                        else:
                                sigm = var.reshape(len(param),len(param)) #covariance matrix
                        return np.random.multivariate_normal(param,sigm,self.num)