scipy.stats.

log#

scipy.stats.log(X, /)[Quelle]#

Natürlicher Logarithmus einer nicht-negativen Zufallsvariablen

Parameter:
XContinuousDistribution

Die Zufallsvariable \(X\) mit positivem Träger.

Rückgabe:
YContinuousDistribution

Eine Zufallsvariable \(Y = \exp(X)\).

Beispiele

Angenommen, wir haben eine Gamma-verteilte Zufallsvariable \(X\)

>>> import numpy as np
>>> from scipy import stats
>>> Gamma = stats.make_distribution(stats.gamma)
>>> X = Gamma(a=1.0)

Wir möchten eine Exponential-Gamma-verteilte Zufallsvariable \(Y\) haben, eine Zufallsvariable, deren natürliche Exponentialfunktion \(X\) ist. Wenn \(X\) die natürliche Exponentialfunktion von \(Y\) sein soll, dann müssen wir \(Y\) als den natürlichen Logarithmus von \(X\) nehmen.

>>> Y = stats.log(X)

Um zu zeigen, dass X die Exponentialfunktion von Y darstellt, plotten wir ein normalisiertes Histogramm der Exponentialfunktion von Beobachtungen von Y gegen die zugrundeliegende Wahrscheinlichkeitsdichtefunktion von X.

>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng()
>>> y = Y.sample(shape=10000, rng=rng)
>>> ax = plt.gca()
>>> ax.hist(np.exp(y), bins=50, density=True)
>>> X.plot(ax=ax)
>>> plt.legend(('PDF of `X`', 'histogram of `exp(y)`'))
>>> plt.show()
../../_images/scipy-stats-log-1.png