Python numpy.euler_gamma() Examples
The following are 9 code examples for showing how to use numpy.euler_gamma(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
You may check out the related API usage on the sidebar.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example 1
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: test_iforest.py License: MIT License | 6 votes |
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))
Example 2
Project: chainer Author: chainer File: test_constants.py License: MIT License | 6 votes |
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
Example 3
Project: GraphicDesignPatternByPython Author: Relph1119 File: _continuous_distns.py License: MIT License | 6 votes |
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)
Example 4
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: iforest.py License: MIT License | 5 votes |
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)
Example 5
Project: GraphicDesignPatternByPython Author: Relph1119 File: _continuous_distns.py License: MIT License | 5 votes |
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
Example 6
Project: Cirq Author: quantumlib File: fidelity_estimation.py License: Apache License 2.0 | 5 votes |
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)))
Example 7
Project: lenstronomy Author: sibirrer File: test_gaussian_ellipse_kappa.py License: MIT License | 5 votes |
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)
Example 8
Project: pypbo Author: esvhd File: pbo.py License: GNU Affero General Public License v3.0 | 5 votes |
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)
Example 9
Project: mixed-anomaly Author: cubonacci File: metrics.py License: Apache License 2.0 | 5 votes |
def average_path_length(sample_size: float) -> float: return 2 * (np.log(sample_size - 1) + np.euler_gamma) - 2 * (sample_size - 1) / sample_size