本文整理匯總了Python中numpy.euler_gamma方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.euler_gamma方法的具體用法?Python numpy.euler_gamma怎麽用?Python numpy.euler_gamma使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy
的用法示例。
在下文中一共展示了numpy.euler_gamma方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_iforest_average_path_length
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def test_iforest_average_path_length():
# It tests non-regression for #8549 which used the wrong formula
# for average path length, strictly for the integer case
# Updated to check average path length when input is <= 2 (issue #11839)
result_one = 2.0 * (np.log(4.0) + np.euler_gamma) - 2.0 * 4.0 / 5.0
result_two = 2.0 * (np.log(998.0) + np.euler_gamma) - 2.0 * 998.0 / 999.0
assert_allclose(_average_path_length([0]), [0.0])
assert_allclose(_average_path_length([1]), [0.0])
assert_allclose(_average_path_length([2]), [1.0])
assert_allclose(_average_path_length([5]), [result_one])
assert_allclose(_average_path_length([999]), [result_two])
assert_allclose(
_average_path_length(np.array([1, 2, 5, 999])),
[0.0, 1.0, result_one, result_two],
)
# _average_path_length is increasing
avg_path_length = _average_path_length(np.arange(5))
assert_array_equal(avg_path_length, np.sort(avg_path_length))
示例2: test_constants
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def test_constants():
assert chainerx.Inf is numpy.Inf
assert chainerx.Infinity is numpy.Infinity
assert chainerx.NAN is numpy.NAN
assert chainerx.NINF is numpy.NINF
assert chainerx.NZERO is numpy.NZERO
assert chainerx.NaN is numpy.NaN
assert chainerx.PINF is numpy.PINF
assert chainerx.PZERO is numpy.PZERO
assert chainerx.e is numpy.e
assert chainerx.euler_gamma is numpy.euler_gamma
assert chainerx.inf is numpy.inf
assert chainerx.infty is numpy.infty
assert chainerx.nan is numpy.nan
assert chainerx.newaxis is numpy.newaxis
assert chainerx.pi is numpy.pi
示例3: _munp
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def _munp(self, n):
if n == 1.0:
return np.log(2) + np.euler_gamma
elif n == 2.0:
return np.pi**2 / 2 + (np.log(2) + np.euler_gamma)**2
elif n == 3.0:
tmp1 = 1.5 * np.pi**2 * (np.log(2)+np.euler_gamma)
tmp2 = (np.log(2)+np.euler_gamma)**3
tmp3 = 14 * sc.zeta(3)
return tmp1 + tmp2 + tmp3
elif n == 4.0:
tmp1 = 4 * 14 * sc.zeta(3) * (np.log(2) + np.euler_gamma)
tmp2 = 3 * np.pi**2 * (np.log(2) + np.euler_gamma)**2
tmp3 = (np.log(2) + np.euler_gamma)**4
tmp4 = 7 * np.pi**4 / 4
return tmp1 + tmp2 + tmp3 + tmp4
else:
# return generic for higher moments
# return rv_continuous._mom1_sc(self, n, b)
return self._mom1_sc(n)
示例4: _average_path_length
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def _average_path_length(n_samples_leaf):
"""The average path length in a n_samples iTree, which is equal to
the average path length of an unsuccessful BST search since the
latter has the same structure as an isolation tree.
Parameters
----------
n_samples_leaf : array-like, shape (n_samples,).
The number of training samples in each test sample leaf, for
each estimators.
Returns
-------
average_path_length : array, same shape as n_samples_leaf
"""
n_samples_leaf = check_array(n_samples_leaf, ensure_2d=False)
n_samples_leaf_shape = n_samples_leaf.shape
n_samples_leaf = n_samples_leaf.reshape((1, -1))
average_path_length = np.zeros(n_samples_leaf.shape)
mask_1 = n_samples_leaf <= 1
mask_2 = n_samples_leaf == 2
not_mask = ~np.logical_or(mask_1, mask_2)
average_path_length[mask_1] = 0.
average_path_length[mask_2] = 1.
average_path_length[not_mask] = (
2.0 * (np.log(n_samples_leaf[not_mask] - 1.0) + np.euler_gamma)
- 2.0 * (n_samples_leaf[not_mask] - 1.0) / n_samples_leaf[not_mask]
)
return average_path_length.reshape(n_samples_leaf_shape)
示例5: _stats
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def _stats(self):
mu = np.log(2) + np.euler_gamma
mu2 = np.pi**2 / 2
g1 = 28 * np.sqrt(2) * sc.zeta(3) / np.pi**3
g2 = 4.
return mu, mu2, g1, g2
示例6: log_xeb_fidelity_from_probabilities
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def log_xeb_fidelity_from_probabilities(
hilbert_space_dimension: int,
probabilities: Sequence[float],
) -> float:
"""Logarithmic XEB fidelity estimator.
Estimates fidelity from ideal probabilities of observed bitstrings.
See `linear_xeb_fidelity_from_probabilities` for the assumptions made
by this estimator.
The mean of this estimator is the true fidelity f and the variance is
(pi^2/6 - f^2) / M
where f is the fidelity and M the number of observations, equal to
len(probabilities). This is better than linear XEB (see above) when
fidelity is f > 0.32. Since this estimator is unbiased, the variance
is equal to the mean squared error of the estimator.
The estimator is intended for use with xeb_fidelity() below.
Args:
hilbert_space_dimension: Dimension of the Hilbert space on which
the channel whose fidelity is being estimated is defined.
probabilities: Ideal probabilities of bitstrings observed in
experiment.
Returns:
Estimate of fidelity associated with an experimental realization
of a quantum circuit.
"""
return (np.log(hilbert_space_dimension) + np.euler_gamma +
np.mean(np.log(probabilities)))
示例7: test_function
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def test_function(self):
"""
Test the `function()` method at the spherical limit.
:return:
:rtype:
"""
# almost spherical case
x = 1.
y = 1.
e1, e2 = 5e-5, 0.
sigma = 1.
amp = 2.
f_ = self.gaussian_kappa_ellipse.function(x, y, amp, sigma, e1, e2)
r2 = x*x + y*y
f_sphere = amp/(2.*np.pi*sigma**2) * sigma**2 * (np.euler_gamma -
expi(-r2/2./sigma**2) + np.log(r2/2./sigma**2))
npt.assert_almost_equal(f_, f_sphere, decimal=4)
# spherical case
e1, e2 = 0., 0.
f_ = self.gaussian_kappa_ellipse.function(x, y, amp, sigma, e1, e2)
npt.assert_almost_equal(f_, f_sphere, decimal=4)
示例8: expected_max
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def expected_max(N):
"""
Expected maximum of IID random variance X_n ~ Z, n = 1,...,N,
where Z is the CDF of the standard Normal distribution,
E[MAX_n] = E[max{x_n}]. Computed for a large N.
"""
if N < 5:
raise AssertionError("Condition N >> 1 not satisfied.")
return (1 - np.euler_gamma) * ss.norm.ppf(
1 - 1.0 / N
) + np.euler_gamma * ss.norm.ppf(1 - np.exp(-1) / N)
示例9: average_path_length
# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import euler_gamma [as 別名]
def average_path_length(sample_size: float) -> float:
return 2 * (np.log(sample_size - 1) + np.euler_gamma) - 2 * (sample_size - 1) / sample_size