Python scipy.stats.norm 模块,rvs() 实例源码

我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用scipy.stats.norm.rvs()

项目:simdna    作者:kundajelab    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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)
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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)
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
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
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_bic_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)
    bics = c.comparison.bic()
    assert len(bics) == 1
    assert bics[0] is None
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_bic_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)
    bics = c.comparison.bic()
    assert len(bics) == 1
    assert bics[0] == 0
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_bic_parameter_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=2, num_eff_data_points=1000)
    bics = c.comparison.bic()
    assert len(bics) == 2
    assert bics[0] == 0
    expected = np.log(1000)
    assert np.isclose(bics[1], expected, atol=1e-3)
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_bic_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)
    bics = c.comparison.bic()
    assert len(bics) == 2
    assert bics[1] == 0
    expected = np.log(1000) - np.log(500)
    assert np.isclose(bics[0], expected, atol=1e-3)
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_bic_data_dependence2():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p, num_free_params=2, num_eff_data_points=1000)
    c.add_chain(d, posterior=p, num_free_params=3, num_eff_data_points=500)
    bics = c.comparison.bic()
    assert len(bics) == 2
    assert bics[0] == 0
    expected = 3 * np.log(500) - 2 * np.log(1000)
    assert np.isclose(bics[1], expected, atol=1e-3)
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_dic_fail_no_posterior():
    d = norm.rvs(size=1000)
    c = ChainConsumer()
    c.add_chain(d, num_eff_data_points=1000, num_free_params=1)
    dics = c.comparison.dic()
    assert len(dics) == 1
    assert dics[0] is None
项目:ChainConsumer    作者:Samreay    | 项目源码 | 文件源码
def test_dic_0():
    d = norm.rvs(size=1000)
    p = norm.logpdf(d)
    c = ChainConsumer()
    c.add_chain(d, posterior=p)
    dics = c.comparison.dic()
    assert len(dics) == 1
    assert dics[0] == 0
项目:pydata-berlin-event-brokering    作者:pierregarreau    | 项目源码 | 文件源码
def get_position(self):
        dt = int(time.time()) - self.ts_now
        is_moving = (random.random() > 0.40)
        if is_moving:
            self.x += norm.rvs(scale=self.delta**2*dt)
            self.y += norm.rvs(scale=self.delta**2*dt)
        self.ts_now += dt
        return {
            'ts': self.ts_now,
            'x': self.x,
            'y': self.y,
            'port_id': BROKER_CLIENT_ID
        }
项目:wavelet-denoising    作者:mackaiver    | 项目源码 | 文件源码
def signal_generator(center=[70, 0], width=1):
    while True:
        yield norm.rvs(loc=center, scale=width)
项目:densratio_py    作者:hoxo-m    | 项目源码 | 文件源码
def test_densratio_1d(self):
        x = norm.rvs(size = 200, loc = 0, scale = 1./8, random_state = 71)
        y = norm.rvs(size = 200, loc = 0, scale = 1./2, random_state = 71)
        result = densratio(x, y)
        self.assertIsNotNone(result)
        density_ratio = result.compute_density_ratio(linspace(-1, 3))
        # print(density_ratio)
项目:densratio_py    作者:hoxo-m    | 项目源码 | 文件源码
def test_densratio_2d(self):
        x = multivariate_normal.rvs(size = 300, mean = [1, 1], cov = [[1./8, 0], [0, 2]], random_state = 71)
        y = multivariate_normal.rvs(size = 300, mean = [1, 1], cov = [[1./2, 0], [0, 2]], random_state = 71)
        result = densratio(x, y)
        self.assertIsNotNone(result)
项目:densratio_py    作者:hoxo-m    | 项目源码 | 文件源码
def test_densratio_dimension_error(self):
        x = norm.rvs(size = 200, loc = 0, scale = 1./8, random_state = 71)
        y = multivariate_normal.rvs(size = 300, mean = [1, 1], cov = [[1./2, 0], [0, 2]], random_state = 71)
        with self.assertRaises(ValueError):
            densratio(x, y)
项目:Building-Machine-Learning-Systems-With-Python-Second-Edition    作者:PacktPublishing    | 项目源码 | 文件源码
def plot_mi_demo():
    np.random.seed(0)  # to reproduce the data later on
    pylab.clf()
    pylab.figure(num=None, figsize=(8, 8))

    x = np.arange(0, 10, 0.2)

    pylab.subplot(221)
    y = 0.5 * x + norm.rvs(1, scale=.01, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(222)
    y = 0.5 * x + norm.rvs(1, scale=.1, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(223)
    y = 0.5 * x + norm.rvs(1, scale=1, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(224)
    y = norm.rvs(1, scale=10, size=len(x))
    _plot_mi_func(x, y)

    pylab.autoscale(tight=True)
    pylab.grid(True)

    filename = "mi_demo_1.png"
    pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")

    pylab.clf()
    pylab.figure(num=None, figsize=(8, 8))

    x = np.arange(-5, 5, 0.2)

    pylab.subplot(221)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=.01, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(222)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=.1, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(223)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=1, size=len(x))
    _plot_mi_func(x, y)

    pylab.subplot(224)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=10, size=len(x))
    _plot_mi_func(x, y)

    pylab.autoscale(tight=True)
    pylab.grid(True)

    filename = "mi_demo_2.png"
    pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")
项目:Building-Machine-Learning-Systems-With-Python-Second-Edition    作者:PacktPublishing    | 项目源码 | 文件源码
def plot_correlation_demo():
    np.random.seed(0)  # to reproduce the data later on
    pylab.clf()
    pylab.figure(num=None, figsize=(8, 8))

    x = np.arange(0, 10, 0.2)

    pylab.subplot(221)
    y = 0.5 * x + norm.rvs(1, scale=.01, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(222)
    y = 0.5 * x + norm.rvs(1, scale=.1, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(223)
    y = 0.5 * x + norm.rvs(1, scale=1, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(224)
    y = norm.rvs(1, scale=10, size=len(x))
    _plot_correlation_func(x, y)

    pylab.autoscale(tight=True)
    pylab.grid(True)

    filename = "corr_demo_1.png"
    pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")

    pylab.clf()
    pylab.figure(num=None, figsize=(8, 8))

    x = np.arange(-5, 5, 0.2)

    pylab.subplot(221)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=.01, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(222)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=.1, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(223)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=1, size=len(x))
    _plot_correlation_func(x, y)

    pylab.subplot(224)
    y = 0.5 * x ** 2 + norm.rvs(1, scale=10, size=len(x))
    _plot_correlation_func(x, y)

    pylab.autoscale(tight=True)
    pylab.grid(True)

    filename = "corr_demo_2.png"
    pylab.savefig(os.path.join(CHART_DIR, filename), bbox_inches="tight")