File:Sample mean and variance of IID samples from a standard Cauchy distribution..png
Original file (1,589 × 490 pixels, file size: 115 KB, MIME type: image/png)
This is a file from the Wikimedia Commons. Information from its description page there is shown below. Commons is a freely licensed media file repository. You can help. |
Summary
DescriptionSample mean and variance of IID samples from a standard Cauchy distribution..png |
English: sample mean and variance of IID samples from a standard Cauchy distribution.
```python import numpy as np import matplotlib.pyplot as plt def running_sample_variance(data): """ Welford's online algorithm to calculate the variance. In each iteration, the mean and M2 (the sum of the squares of differences from the mean) are updated. For each column i, the difference delta between the current data point and the previous mean is calculated, and the mean and M2 are updated accordingly. variance = M2 / np.arange(1, m + 1). """ n, m = data.shape mean = np.zeros((n, m)) M2 = np.zeros((n, m)) for i in range(m): if i == 0: delta = data[:, i] - mean[:, i] mean[:, i] = mean[:, i] + delta / (i + 1) M2[:, i] = delta * (data[:, i] - mean[:, i]) else: delta = data[:, i] - mean[:, i - 1] mean[:, i] = mean[:, i - 1] + delta / (i + 1) M2[:, i] = M2[:, i - 1] + delta * (data[:, i] - mean[:, i]) variance_n = M2 / (np.arange(1, m + 1)) return variance_n def running_sample_average(data): cumsum = np.cumsum(data, axis=1) cum_n = np.arange(1, data.shape[1] + 1) return cumsum / cum_n
n = 10 # Number of rows m = 500000 # Number of columns
data = np.random.standard_cauchy(size=(n, m)) variances = running_sample_variance(data) mean = running_sample_average(data)
fig, (ax2, ax1) = plt.subplots(1, 2, figsize=(16, 5))
x = np.arange(1, variances.shape[1] + 1) ax1.semilogy(variances.T, linewidth=1) ax1.set_xlabel('Number of Samples') ax1.set_ylabel('Variance') ax1.set_title('Running Sample Variances')
ax2.semilogy(np.abs(mean.T), linewidth=1) ax2.set_xlabel('Number of Samples') ax2.set_ylabel('Average (absolute value)') ax2.set_title('Running Sample Averages')
plt.tight_layout() plt.show() ``` |
Date | |
Source | Own work |
Author | Cosmia Nebula |
Licensing
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.
- share alike – If you remix, transform, or build upon the material, you must distribute your contributions under the same or compatible license as the original.
This media file is uncategorized.
Please help improve this media file by adding it to one or more categories, so it may be associated with related media files (how?), and so that it can be more easily found.
Please notify the uploader with {{subst:Please link images|File:Sample mean and variance of IID samples from a standard Cauchy distribution..png}} ~~~~ |
Items portrayed in this file
depicts
some value
2 June 2023
image/png
File history
Click on a date/time to view the file as it appeared at that time.
Date/Time | Thumbnail | Dimensions | User | Comment | |
---|---|---|---|---|---|
current | 21:17, 2 June 2023 | 1,589 × 490 (115 KB) | Cosmia Nebula | Uploaded while editing "Cauchy distribution" on en.wikipedia.org |
File usage
The following page uses this file:
Metadata
This file contains additional information, probably added from the digital camera or scanner used to create or digitize it.
If the file has been modified from its original state, some details may not fully reflect the modified file.
Software used | |
---|---|
Horizontal resolution | 39.37 dpc |
Vertical resolution | 39.37 dpc |