File:BetaDistrMedianApprDiff.svg

Uploaded by Shiyu Ji
Upload date 2017-10-08T05:57:16Z
MIME type image/svg+xml
Dimensions 720 × 540 px
File size 1.2 MB

Summary

Description
English: Relative Error for Approximation to Median of Beta Distribution for alpha and beta from 1 to 5.
Date
Source Own work
Author Shiyu Ji
Other versions
A raster version of this image is available. It should be used in place of this vector image when superior.

In general, it is better to use a good SVG version.


Bitmap image
SVG development
InfoField
 The source code of this SVG is invalid due to an error.
 This W3C-invalid plot was created with Matplotlib.

Python Source Code

# Beta distribution median-appr rel diff.
# Idea from Dr. J. Rodal
# Use Inkscape to enlarge and adjust the figure position
# (degroup, enlarge and regroup the SVG elements etc.).

from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as pl
from matplotlib import cm
import numpy as np
from scipy.special import betainc
import scipy.integrate as integral

# binary search the root I_x(alpha, beta) = 0.5
def binary_search(a, b, result, err):
  low, high = 0.0, 1.0
  while low + err < high:
    mid = (low + high)/2.0
    if abs(betainc(a, b, mid) - result) < err:
      return mid
    elif betainc(a, b, mid) < result:
      low = mid
    else: high = mid
  return low

# Prepare the data.
A = np.arange(1.01, 5.0, .01)
B = np.arange(1.01, 5.0, .01)
gridA, gridB = np.meshgrid(A, B)
Z = np.ndarray(shape=gridA.shape, dtype = float)
for i in range(len(A)):
  for j in range(len(B)):
    median = binary_search(A[i], B[j], 0.5, err = 1e-7)
    appr   = (A[i] - 1/3.0) / (A[i] + B[j] - 2/3.0)
    Z[j][i] = abs(median - appr) / median
# Draw the data
fig = pl.figure()
ax = fig.add_subplot(111, projection = '3d')
pl.xticks([1, 2, 3, 4, 5])
pl.yticks([1, 2, 3, 4, 5])
ax.contour(gridA, gridB, Z, zdir='z', offset=-.45)
ax.plot_surface(gridA, gridB, Z, lw = 0.0)
ax.plot_wireframe(gridA, gridB, Z, lw = 1.0, color = 'black', \
   rstride=20, cstride=20)
ax.set_xlim([1.0, 5.0])
ax.set_ylim([1.0, 5.0])
ax.set_xlabel('alpha')
ax.set_ylabel('beta')
ax.set_zlabel('Rel. Error')
ax.view_init(20,30)
fig.savefig('betaDistrMedianApprDiff.svg')

Licensing

Shiyu Ji, the copyright holder of this work, hereby publishes it under the following license:
w:en:Creative Commons
attribution share alike
This file is licensed under the Creative Commons Attribution-Share Alike 4.0 International license.
Attribution:
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.

Captions

Add a one-line explanation of what this file represents

Items portrayed in this file

depicts

8 October 2017

image/svg+xml

5bc753b01ff01469c7ec0142afd414f0b6de96d4

1,259,777 byte

540 pixel

720 pixel

Category:Beta distribution Category:Bitmap version available Category:CC-BY-SA-4.0 Category:Invalid SVG created with Matplotlib Category:SVG surface plots Category:Self-published work