当前位置: 首页>>代码示例>>Python>>正文


Python norm.rvs方法代码示例

本文整理汇总了Python中scipy.stats.norm.rvs方法的典型用法代码示例。如果您正苦于以下问题:Python norm.rvs方法的具体用法?Python norm.rvs怎么用?Python norm.rvs使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.stats.norm的用法示例。


在下文中一共展示了norm.rvs方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: weiner_process_fn

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def weiner_process_fn(num_points, delta, x0=0, dt=1):
    """
    Generates Weiner process realisation trajectory.

    Args:
        num_points:     int, trajectory length;
        delta:          float, speed parameter;
        x0:             float, starting point;
        dt:             int, time increment;

    Returns:
        generated data as 1D np.array
    """
    x0 = np.asarray(x0)
    r = norm.rvs(size=x0.shape + (num_points,), scale=delta * (dt**.5))

    return np.cumsum(r, axis=-1) + np.expand_dims(x0, axis=-1) 
开发者ID:Kismuz,项目名称:btgym,代码行数:19,代码来源:stochastic.py

示例2: impute

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def impute(self, X):
        """Generate imputations using predictions from the fit linear model.

        The impute method returns the values for imputation. Missing values
        in a given dataset are replaced with the predictions from the least
        squares regression line of best fit plus a random draw from the normal
        error distribution.

        Args:
            X (pd.DataFrame): predictors to determine imputed values.

        Returns:
            np.array: imputed dataset.
        """
        # check if fitted then predict with least squares
        check_is_fitted(self, "statistics_")
        mse = self.statistics_["param"]
        preds = self.lm.predict(X)

        # add random draw from normal dist w/ mean squared error
        # from observed model. This makes lm stochastic
        mse_dist = norm.rvs(loc=0, scale=sqrt(mse), size=len(preds))
        imp = preds + mse_dist
        return imp 
开发者ID:kearnz,项目名称:autoimpute,代码行数:26,代码来源:linear_regression.py

示例3: _generatePos

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def _generatePos(self, lenBackground, lenSubstring, additionalInfo):
        from scipy.stats import norm
        center = (lenBackground-lenSubstring)/2.0
        validPos = False
        totalTries = 0
        while (validPos == False):
            sampledPos = int(norm.rvs(loc=center+self.offsetFromCenter,
                          scale=self.stdInBp))
            totalTries += 1
            if (sampledPos > 0 and sampledPos < (lenBackground-lenSubstring)):
                validPos = True
            if (totalTries%10 == 0 and totalTries > 0):
                print("Warning: made "+str(totalTries)+" attempts at sampling"
                      +" a position with lenBackground "+str(lenBackground)
                      +" and center "+str(center)+" and offset "
                      +str(self.offsetFromCenter)) 
        return sampledPos 
开发者ID:kundajelab,项目名称:simdna,代码行数:19,代码来源:positiongen.py

示例4: impute

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def impute(self, feature=None, strategy=None, distribution=None):
        if self._matrix is None:
            raise ValueError('Must call set_input_matrix() before impute().')
        # If user does not specify which feature to impute, impute values
        # for all columns in the matrix.
        if feature is None:
            feature = FeatureMatrixTransform.ALL_FEATURES

        # If an imputation strategy is not specified, default to mean.
        if strategy is None:
            strategy = FeatureMatrixTransform.IMPUTE_STRATEGY_MEAN

        # If distribution is not specified, default to norm.
        if distribution is None:
            distribution = norm.rvs

        # TODO sxu: modify other modules to also return stuff
        if feature == FeatureMatrixTransform.ALL_FEATURES:
            self._impute_all_features(strategy, distribution=distribution)
        else:
            return self._impute_single_feature(feature, strategy, distribution=distribution) 
开发者ID:HealthRex,项目名称:CDSS,代码行数:23,代码来源:FeatureMatrixTransform.py

示例5: ou_process_t_driver_batch_fn

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def ou_process_t_driver_batch_fn(num_points, mu, l, sigma, df, x0, dt=1):
    """
    Generates batch of realisation trajectories of Ornshtein-Uhlenbeck process
    driven by t-distributed innovations.

    Args:
        num_points:     int, trajectory length
        mu:             float or array of shape [batch_dim], mean;
        l:              float or array of shape [batch_dim], lambda, mean reversion rate;
        sigma:          float or array of shape [batch_dim], volatility;
        df:             float or array of shape [batch_dim] > 2.0, standart Student-t degrees of freedom param.;
        x0:             float or array of shape [batch_dim], starting point;
        dt:             int, time increment;

    Returns:
        generated data as np.array of shape [batch_dim, num_points]
    """

    n = num_points + 1
    try:
        batch_dim = x0.shape[0]
        x = np.zeros([n, batch_dim])
        x[0, :] = np.squeeze(x0)
    except (AttributeError, IndexError) as e:
        batch_dim = None
        x = np.zeros([n, 1])
        x[0, :] = x0

    for i in range(1, n):
        driver = np.random.standard_t(df, size=df.size) * ((df - 2) / df) ** .5
        # driver = stats.t.rvs(df, loc, scale, size=batch_dim)
        # x_vol = df / (df - 2)
        # driver = (driver - loc) / scale / x_vol**.5
        x[i, :] = x[i - 1, :] * np.exp(-l * dt) + mu * (1 - np.exp(-l * dt)) + \
            sigma * ((1 - np.exp(-2 * l * dt)) / (2 * l)) ** .5 * driver

    return x[1:, :] 
开发者ID:Kismuz,项目名称:btgym,代码行数:39,代码来源:stochastic.py

示例6: rnorm

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def rnorm(n,mean,sd):
    """
    same functions as rnorm in r
    r: rnorm(n, mean=0, sd=1)
    py: rvs(loc=0, scale=1, size=1, random_state=None)
    """
    return norm.rvs(loc=mean,scale=sd,size=n) 
开发者ID:runawayhorse001,项目名称:LearningApacheSpark,代码行数:9,代码来源:mcmc.py

示例7: evolve

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def evolve(self):
        X = self.state
        dw = norm.rvs(scale=self.dt, size=self.processes)
        dx = self.theta * (self.mu - X) * self.dt + self.sigma * dw
        self.state = X + dx
        return self.state 
开发者ID:knowledgedefinednetworking,项目名称:a-deep-rl-approach-for-sdn-routing-optimization,代码行数:8,代码来源:OU.py

示例8: test_aic_fail_no_posterior

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_fail_no_posterior():
    d = norm.rvs(size=1000)
    c = ChainConsumer()
    c.add_chain(d, num_eff_data_points=1000, num_free_params=1)
    aics = c.comparison.aic()
    assert len(aics) == 1
    assert aics[0] is None 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:9,代码来源:test_comparisons.py

示例9: test_aic_fail_no_data_points

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_fail_no_data_points():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=1)
    aics = c.comparison.aic()
    assert len(aics) == 1
    assert aics[0] is None 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:10,代码来源:test_comparisons.py

示例10: test_aic_fail_no_num_params

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_fail_no_num_params():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_eff_data_points=1000)
    aics = c.comparison.aic()
    assert len(aics) == 1
    assert aics[0] is None 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:10,代码来源:test_comparisons.py

示例11: test_aic_0

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_0():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=1000)
    aics = c.comparison.aic()
    assert len(aics) == 1
    assert aics[0] == 0 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:10,代码来源:test_comparisons.py

示例12: test_aic_posterior_dependence

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_posterior_dependence():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    p2 = norm.logpdf(d, scale=2)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=1000)
    c.add_chain(d, posterior=p2, num_free_params=1, num_eff_data_points=1000)
    aics = c.comparison.aic()
    assert len(aics) == 2
    assert aics[0] == 0
    expected = 2 * np.log(2)
    assert np.isclose(aics[1], expected, atol=1e-3) 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:14,代码来源:test_comparisons.py

示例13: test_aic_data_dependence

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_aic_data_dependence():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=1000)
    c.add_chain(d, posterior=p, num_free_params=1, num_eff_data_points=500)
    aics = c.comparison.aic()
    assert len(aics) == 2
    assert aics[0] == 0
    expected = (2.0 * 1 * 2 / (500 - 1 - 1)) - (2.0 * 1 * 2 / (1000 - 1 - 1))
    assert np.isclose(aics[1], expected, atol=1e-3) 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:13,代码来源:test_comparisons.py

示例14: test_bic_fail_no_posterior

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_bic_fail_no_posterior():
    d = norm.rvs(size=1000)
    c = ChainConsumer()
    c.add_chain(d, num_eff_data_points=1000, num_free_params=1)
    bics = c.comparison.bic()
    assert len(bics) == 1
    assert bics[0] is None 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:9,代码来源:test_comparisons.py

示例15: test_bic_fail_no_data_points

# 需要导入模块: from scipy.stats import norm [as 别名]
# 或者: from scipy.stats.norm import rvs [as 别名]
def test_bic_fail_no_data_points():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=1)
    bics = c.comparison.bic()
    assert len(bics) == 1
    assert bics[0] is None 
开发者ID:Samreay,项目名称:ChainConsumer,代码行数:10,代码来源:test_comparisons.py


注:本文中的scipy.stats.norm.rvs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。