Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barrbrain/e4304ec3d75ffebb50f8bc531282e98b to your computer and use it in GitHub Desktop.
Save barrbrain/e4304ec3d75ffebb50f8bc531282e98b to your computer and use it in GitHub Desktop.
Aggregate quantizer-bitrate statistics
#!/usr/bin/env python
import matplotlib as mpl
mpl.use('Agg')
from matplotlib import pyplot as plt
import numpy as np
from pprint import pprint
from glob import glob
# Klotz, Jerome H. "UPDATING SIMPLE LINEAR REGRESSION."
# Statistica Sinica 5, no. 1 (1995): 399-403.
# http://www.jstor.org/stable/24305577
def online_simple_regression(accumulator, x, y):
Ax_, Ay_, Sxy, Sxx, n_, miny, maxy = accumulator or (0, 0, 0, 0, 0, 0, 0)
first = n_ == 0
n = n_ + x.size
rt_n, rt_n_ = np.sqrt((n, n_), dtype=np.float128)
Ax = (Ax_*n_ + x.sum(dtype=np.float128))/n
Ay = (Ay_*n_ + y.sum(dtype=np.float128))/n
miny = min(miny, y.min())
maxy = max(maxy, y.max())
X = Ax if first else (Ax_*rt_n_ + Ax*rt_n)/(rt_n_ + rt_n)
Y = Ay if first else (Ay_*rt_n_ + Ay*rt_n)/(rt_n_ + rt_n)
Sxx += np.sum((x - X)**2)
Sxy += np.sum((x - X)*(y - Y))
return Ax, Ay, Sxy, Sxx, n, miny, maxy
def conv_px(s):
w, h = s.split(b'x')
return int(w)*int(h)
conv_fti = [b'I', b'P', b'B0', b'B1'].index
def collect(filename, queues):
px, log_target_q, byte_size, frame_type = np.loadtxt(
filename, dtype=np.int64, delimiter=',',
converters={1: conv_px, 4: conv_fti},
skiprows=1, usecols=range(1, 5), unpack=True)
blog64q57_ibpp = np.round((
np.log2(px, dtype=np.float128) - np.log2(byte_size*8, dtype=np.float128)
)*2**57).astype(np.int64)
for fti in np.unique(frame_type):
x, y = log_target_q[frame_type==fti], blog64q57_ibpp[frame_type==fti]
queue = queues.get(fti, ([], []))
queue[0].append(x)
queue[1].append(y)
queues[fti] = queue
def aggregate(queues, partials):
for fti, queue in queues.items():
x, y = np.concatenate(queue[0]), np.concatenate(queue[1])
partials[fti] = online_simple_regression(partials.get(fti, None), x, y)
partials = dict()
for base in sorted(glob('*.y4m')):
queues = dict()
for q in range(1, 256):
collect('%s/%d.txt' % (base, q), queues)
aggregate(queues, partials)
pprint(partials)
plt.figure(figsize=(7, 6))
plt.axis('equal')
plt.xticks([0, 10])
plt.yticks([0, 10])
plt.minorticks_on()
plt.grid(b=True, which='major')
plt.grid(b=True, which='minor', alpha=0.2)
for fti, accumulator in partials.items():
Ax, Ay, Sxy, Sxx, n, miny, maxy = accumulator
beta = Sxy/Sxx
alpha = Ay - beta*Ax
scale = int(np.round(np.exp2(3 - alpha/2**57)))
exp = int(np.round(beta*2**6))
label = ['I', 'P', 'B0', 'B1'][fti]
print('%2s: exp=%d scale=%d' % (label, exp, scale))
ys = [miny/2**57, maxy/2**57]
xs = [(ys[0] - alpha/2**57)/beta, (ys[1] - alpha/2**57)/beta]
plt.plot(xs, ys, label=label)
plt.legend()
plt.savefig('log-bitrate_wrt_log-quantizer.png')
plt.clf()
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"scrolled": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{0: (5.938885278876450718e+17,\n",
" 1.9137710889304368723e+17,\n",
" 2.410941997325506283e+40,\n",
" 2.4723415216574388483e+40,\n",
" 337110,\n",
" -479784840691660528,\n",
" 1428504883828996212),\n",
" 1: (6.505176872133070449e+17,\n",
" 5.7400758576573096778e+17,\n",
" 2.9449582682435935951e+41,\n",
" 1.9503819765026800224e+41,\n",
" 2659395,\n",
" -430456311176036496,\n",
" 2134890862486819534),\n",
" 2: (7.071468465389690206e+17,\n",
" 8.0193697664877629525e+17,\n",
" 2.9225410017825442604e+41,\n",
" 1.9821745679309526856e+41,\n",
" 2702745,\n",
" -392114462299251034,\n",
" 1791224583212461071),\n",
" 3: (7.637760058646309966e+17,\n",
" 9.827995667253292844e+17,\n",
" 5.475769590533601731e+41,\n",
" 3.9548113584334235726e+41,\n",
" 5392485,\n",
" -369660646353102446,\n",
" 1993683613661377668)}\n"
]
}
],
"source": [
"%matplotlib inline\n",
"from IPython.display import set_matplotlib_formats\n",
"set_matplotlib_formats('svg')\n",
"\n",
"from glob import glob\n",
"from matplotlib import pyplot as plt\n",
"import numpy as np\n",
"from pprint import pprint\n",
"\n",
"# Klotz, Jerome H. \"UPDATING SIMPLE LINEAR REGRESSION.\"\n",
"# Statistica Sinica 5, no. 1 (1995): 399-403.\n",
"# http://www.jstor.org/stable/24305577\n",
"def online_simple_regression(accumulator, x, y):\n",
" Ax_, Ay_, Sxy, Sxx, n_, miny, maxy = accumulator or (0, 0, 0, 0, 0, 0, 0)\n",
"\n",
" first = n_ == 0\n",
" n = n_ + x.size\n",
" rt_n, rt_n_ = np.sqrt((n, n_), dtype=np.float128)\n",
"\n",
" Ax = (Ax_*n_ + x.sum(dtype=np.float128))/n\n",
" Ay = (Ay_*n_ + y.sum(dtype=np.float128))/n\n",
" \n",
" miny = min(miny, y.min())\n",
" maxy = max(maxy, y.max())\n",
" \n",
" X = Ax if first else (Ax_*rt_n_ + Ax*rt_n)/(rt_n_ + rt_n)\n",
" Y = Ay if first else (Ay_*rt_n_ + Ay*rt_n)/(rt_n_ + rt_n)\n",
"\n",
" Sxx += np.sum((x - X)**2)\n",
" Sxy += np.sum((x - X)*(y - Y))\n",
"\n",
" return Ax, Ay, Sxy, Sxx, n, miny, maxy\n",
"\n",
"def conv_px(s):\n",
" w, h = s.split(b'x')\n",
" return int(w)*int(h)\n",
"\n",
"conv_fti = [b'I', b'P', b'B0', b'B1'].index\n",
"\n",
"def collect(filename, queues):\n",
" px, log_target_q, byte_size, frame_type = np.loadtxt(\n",
" filename, dtype=np.int64, delimiter=',',\n",
" converters={1: conv_px, 4: conv_fti},\n",
" skiprows=1, usecols=range(1, 5), unpack=True)\n",
"\n",
" blog64q57_ibpp = np.round((\n",
" np.log2(px, dtype=np.float128) - np.log2(byte_size*8, dtype=np.float128)\n",
" )*2**57).astype(np.int64)\n",
"\n",
" for fti in np.unique(frame_type):\n",
" x, y = log_target_q[frame_type==fti], blog64q57_ibpp[frame_type==fti]\n",
" queue = queues.get(fti, ([], []))\n",
" queue[0].append(x)\n",
" queue[1].append(y)\n",
" queues[fti] = queue\n",
"\n",
"def aggregate(queues, partials):\n",
" for fti, queue in queues.items():\n",
" x, y = np.concatenate(queue[0]), np.concatenate(queue[1])\n",
" partials[fti] = online_simple_regression(partials.get(fti, None), x, y)\n",
"\n",
"partials = dict()\n",
"for base in sorted(glob('*.y4m')):\n",
" queues = dict()\n",
" for q in range(1, 256):\n",
" collect('%s/%d.txt' % (base, q), queues)\n",
" aggregate(queues, partials)\n",
"pprint(partials)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" I: exp=62 scale=52\n",
" P: exp=97 scale=57\n",
"B0: exp=94 scale=25\n",
"B1: exp=89 scale=11\n"
]
},
{
"data": {
"image/svg+xml": [
"<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>\n",
"<svg width=\"428pt\" height=\"361pt\" version=\"1.1\" viewBox=\"0 0 428 361\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<defs>\n",
"<style type=\"text/css\">*{stroke-linecap:butt;stroke-linejoin:round;}</style>\n",
"</defs>\n",
"<path d=\"m0 361h428v-361h-428z\" fill=\"none\"/>\n",
"<path d=\"m26.9 337h391v-326h-391z\" fill=\"#fff\"/>\n",
"<path d=\"m129 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<defs>\n",
"<path id=\"g\" d=\"m0 0v3.5\" stroke=\"#000\" stroke-width=\".8\"/>\n",
"</defs>\n",
"<use x=\"128.696843\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".8\" xlink:href=\"#g\"/>\n",
"<defs>\n",
"<path id=\"d\" d=\"m31.8 66.4q-7.61 0-11.5-7.5-3.83-7.48-3.83-22.5 0-15 3.83-22.5 3.84-7.5 11.5-7.5 7.67 0 11.5 7.5 3.84 7.5 3.84 22.5 0 15-3.84 22.5-3.83 7.5-11.5 7.5zm0 7.81q12.3 0 18.7-9.7 6.47-9.69 6.47-28.1 0-18.4-6.47-28.1-6.47-9.69-18.7-9.69-12.2 0-18.7 9.69-6.47 9.7-6.47 28.1 0 18.5 6.47 28.1 6.47 9.7 18.7 9.7z\"/>\n",
"</defs>\n",
"<g transform=\"translate(126 351) scale(.1 -.1)\">\n",
"<use xlink:href=\"#d\"/>\n",
"</g>\n",
"<path d=\"m292 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<use x=\"292.126149\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".8\" xlink:href=\"#g\"/>\n",
"<defs>\n",
"<path id=\"e\" d=\"m12.4 8.3h16.1v55.6l-17.5-3.52v8.98l17.4 3.52h9.86v-64.6h16.1v-8.3h-42z\"/>\n",
"</defs>\n",
"<g transform=\"translate(286 351) scale(.1 -.1)\">\n",
"<use xlink:href=\"#e\"/>\n",
"<use x=\"63.623047\" xlink:href=\"#d\"/>\n",
"</g>\n",
"<path d=\"m30.6 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<defs>\n",
"<path id=\"b\" d=\"m0 0v2\" stroke=\"#000\" stroke-width=\".6\"/>\n",
"</defs>\n",
"<use x=\"30.63926\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m63.3 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"63.325121\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m96 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"96.010982\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m161 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"161.382704\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m194 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"194.068565\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m227 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"226.754426\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m259 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"259.440288\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m325 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"324.81201\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m357 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"357.497871\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m390 337v-326\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"390.183732\" y=\"336.86\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#b\"/>\n",
"<path d=\"m26.9 268h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<defs>\n",
"<path id=\"f\" d=\"m0 0h-3.5\" stroke=\"#000\" stroke-width=\".8\"/>\n",
"</defs>\n",
"<use x=\"26.925\" y=\"267.626052\" stroke=\"#000000\" stroke-width=\".8\" xlink:href=\"#f\"/>\n",
"<g transform=\"translate(13.6 271) scale(.1 -.1)\">\n",
"<use xlink:href=\"#d\"/>\n",
"</g>\n",
"<path d=\"m26.9 104h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"104.196746\" stroke=\"#000000\" stroke-width=\".8\" xlink:href=\"#f\"/>\n",
"<g transform=\"translate(7.2 108) scale(.1 -.1)\">\n",
"<use xlink:href=\"#e\"/>\n",
"<use x=\"63.623047\" xlink:href=\"#d\"/>\n",
"</g>\n",
"<path d=\"m26.9 333h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<defs>\n",
"<path id=\"c\" d=\"m0 0h-2\" stroke=\"#000\" stroke-width=\".6\"/>\n",
"</defs>\n",
"<use x=\"26.925\" y=\"332.997774\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 300h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"300.311913\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 235h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"234.940191\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 202h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"202.254329\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 170h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"169.568468\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 137h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"136.882607\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 71.5h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"71.510885\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m26.9 38.8h391\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#b0b0b0\" stroke-linecap=\"square\" stroke-opacity=\".2\" stroke-width=\".8\"/>\n",
"<use x=\"26.925\" y=\"38.825024\" stroke=\"#000000\" stroke-width=\".6\" xlink:href=\"#c\"/>\n",
"<path d=\"m118 322 222-216\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#1f77b4\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<path d=\"m127 316 193-291\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#ff7f0e\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<path d=\"m117 312 168-248\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#2ca02c\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<path d=\"m105 310 194-268\" clip-path=\"url(#a)\" fill=\"none\" stroke=\"#d62728\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<path d=\"m26.9 337v-326\" fill=\"none\" stroke=\"#000\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<path d=\"m418 337v-326\" fill=\"none\" stroke=\"#000\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<path d=\"m26.9 337h391\" fill=\"none\" stroke=\"#000\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<path d=\"m26.9 10.7h391\" fill=\"none\" stroke=\"#000\" stroke-linecap=\"square\" stroke-width=\".8\"/>\n",
"<path d=\"m365 77.4h45.2q2 0 2-2v-57.7q0-2-2-2h-45.2q-2 0-2 2v57.7q0 2 2 2z\" fill=\"#fff\" opacity=\".8\" stroke=\"#ccc\"/>\n",
"<path d=\"m367 23.8h20\" fill=\"none\" stroke=\"#1f77b4\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<defs>\n",
"<path id=\"j\" d=\"m9.81 72.9h9.86v-72.9h-9.86z\"/>\n",
"</defs>\n",
"<g transform=\"translate(395 27.3) scale(.1 -.1)\">\n",
"<use xlink:href=\"#j\"/>\n",
"</g>\n",
"<path d=\"m367 38.5h20\" fill=\"none\" stroke=\"#ff7f0e\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<defs>\n",
"<path id=\"i\" d=\"m19.7 64.8v-27.4h12.4q6.89 0 10.6 3.56 3.77 3.56 3.77 10.2 0 6.55-3.77 10.1-3.75 3.56-10.6 3.56zm-9.86 8.11h22.3q12.3 0 18.5-5.55 6.28-5.55 6.28-16.2 0-10.8-6.28-16.3-6.27-5.52-18.5-5.52h-12.4v-29.3h-9.86z\"/>\n",
"</defs>\n",
"<g transform=\"translate(395 42) scale(.1 -.1)\">\n",
"<use xlink:href=\"#i\"/>\n",
"</g>\n",
"<path d=\"m367 53.2h20\" fill=\"none\" stroke=\"#2ca02c\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<defs>\n",
"<path id=\"h\" d=\"m19.7 34.8v-26.7h15.8q7.95 0 11.8 3.3 3.84 3.3 3.84 10.1 0 6.84-3.84 10.1-3.83 3.25-11.8 3.25zm0 30v-22h14.6q7.22 0 10.8 2.7 3.55 2.72 3.55 8.28 0 5.52-3.55 8.25-3.53 2.73-10.8 2.73zm-9.86 8.11h25.2q11.3 0 17.4-4.69 6.11-4.69 6.11-13.3 0-6.7-3.12-10.7t-9.19-4.92q7.28-1.56 11.3-6.53 4.03-4.95 4.03-12.4 0-9.77-6.64-15.1-6.64-5.31-18.9-5.31h-26.2z\"/>\n",
"</defs>\n",
"<g transform=\"translate(395 56.7) scale(.1 -.1)\">\n",
"<use xlink:href=\"#h\"/>\n",
"<use x=\"68.603516\" xlink:href=\"#d\"/>\n",
"</g>\n",
"<path d=\"m367 67.8h20\" fill=\"none\" stroke=\"#d62728\" stroke-linecap=\"square\" stroke-width=\"1.5\"/>\n",
"<g transform=\"translate(395 71.3) scale(.1 -.1)\">\n",
"<use xlink:href=\"#h\"/>\n",
"<use x=\"68.603516\" xlink:href=\"#e\"/>\n",
"</g>\n",
"<defs>\n",
"<clipPath id=\"a\">\n",
"<rect x=\"26.9\" y=\"10.7\" width=\"391\" height=\"326\"/>\n",
"</clipPath>\n",
"</defs>\n",
"</svg>\n"
],
"text/plain": [
"<Figure size 504x432 with 1 Axes>"
]
},
"metadata": {
"needs_background": "light"
},
"output_type": "display_data"
}
],
"source": [
"plt.figure(figsize=(7, 6))\n",
"plt.axis('equal')\n",
"plt.xticks([0, 10])\n",
"plt.yticks([0, 10])\n",
"plt.minorticks_on()\n",
"plt.grid(b=True, which='major')\n",
"plt.grid(b=True, which='minor', alpha=0.2)\n",
"\n",
"for fti, accumulator in partials.items():\n",
" Ax, Ay, Sxy, Sxx, n, miny, maxy = accumulator\n",
"\n",
" beta = Sxy/Sxx\n",
" alpha = Ay - beta*Ax\n",
" scale = int(np.round(np.exp2(3 - alpha/2**57)))\n",
" exp = int(np.round(beta*2**6))\n",
" label = ['I', 'P', 'B0', 'B1'][fti]\n",
" print('%2s: exp=%d scale=%d' % (label, exp, scale))\n",
"\n",
" ys = [miny/2**57, maxy/2**57]\n",
" xs = [(ys[0] - alpha/2**57)/beta, (ys[1] - alpha/2**57)/beta]\n",
" plt.plot(xs, ys, label=label)\n",
"\n",
"plt.legend();"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment