From 0d64b26998b22780b301ab6ab3104afcf6d39c23 Mon Sep 17 00:00:00 2001 From: Andrew Fitzgibbon Date: Wed, 11 Oct 2023 21:13:07 +0100 Subject: [PATCH] Add comments, sparsity calculations --- notebooks/binom_factor_table.ipynb | 263 +++++++++++++++++++++-------- 1 file changed, 192 insertions(+), 71 deletions(-) diff --git a/notebooks/binom_factor_table.ipynb b/notebooks/binom_factor_table.ipynb index 4e095dc..b096c0f 100644 --- a/notebooks/binom_factor_table.ipynb +++ b/notebooks/binom_factor_table.ipynb @@ -42,7 +42,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "kilobytes=12.20703125\n" + "kilobytes=128.0\n" ] } ], @@ -186,15 +186,18 @@ { "data": { "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}1 & b & b^{2} & b^{3} & b^{4}\\\\a & a b & a b^{2} & a b^{3} & a b^{4}\\\\a^{2} & a^{2} b & a^{2} b^{2} & a^{2} b^{3} & a^{2} b^{4}\\\\a^{3} & a^{3} b & a^{3} b^{2} & a^{3} b^{3} & a^{3} b^{4}\\\\a^{4} & a^{4} b & a^{4} b^{2} & a^{4} b^{3} & a^{4} b^{4}\\end{matrix}\\right]$" + "$\\displaystyle \\left[\\begin{matrix}1 & b & b^{2} & b^{3} & b^{4} & b^{5} & b^{6} & b^{7}\\\\a & a b & a b^{2} & a b^{3} & a b^{4} & a b^{5} & a b^{6} & a b^{7}\\\\a^{2} & a^{2} b & a^{2} b^{2} & a^{2} b^{3} & a^{2} b^{4} & a^{2} b^{5} & a^{2} b^{6} & a^{2} b^{7}\\\\a^{3} & a^{3} b & a^{3} b^{2} & a^{3} b^{3} & a^{3} b^{4} & a^{3} b^{5} & a^{3} b^{6} & a^{3} b^{7}\\\\a^{4} & a^{4} b & a^{4} b^{2} & a^{4} b^{3} & a^{4} b^{4} & a^{4} b^{5} & a^{4} b^{6} & a^{4} b^{7}\\\\a^{5} & a^{5} b & a^{5} b^{2} & a^{5} b^{3} & a^{5} b^{4} & a^{5} b^{5} & a^{5} b^{6} & a^{5} b^{7}\\\\a^{6} & a^{6} b & a^{6} b^{2} & a^{6} b^{3} & a^{6} b^{4} & a^{6} b^{5} & a^{6} b^{6} & a^{6} b^{7}\\\\a^{7} & a^{7} b & a^{7} b^{2} & a^{7} b^{3} & a^{7} b^{4} & a^{7} b^{5} & a^{7} b^{6} & a^{7} b^{7}\\end{matrix}\\right]$" ], "text/plain": [ "Matrix([\n", - "[ 1, b, b**2, b**3, b**4],\n", - "[ a, a*b, a*b**2, a*b**3, a*b**4],\n", - "[a**2, a**2*b, a**2*b**2, a**2*b**3, a**2*b**4],\n", - "[a**3, a**3*b, a**3*b**2, a**3*b**3, a**3*b**4],\n", - "[a**4, a**4*b, a**4*b**2, a**4*b**3, a**4*b**4]])" + "[ 1, b, b**2, b**3, b**4, b**5, b**6, b**7],\n", + "[ a, a*b, a*b**2, a*b**3, a*b**4, a*b**5, a*b**6, a*b**7],\n", + "[a**2, a**2*b, a**2*b**2, a**2*b**3, a**2*b**4, a**2*b**5, a**2*b**6, a**2*b**7],\n", + "[a**3, a**3*b, a**3*b**2, a**3*b**3, a**3*b**4, a**3*b**5, a**3*b**6, a**3*b**7],\n", + "[a**4, a**4*b, a**4*b**2, a**4*b**3, a**4*b**4, a**4*b**5, a**4*b**6, a**4*b**7],\n", + "[a**5, a**5*b, a**5*b**2, a**5*b**3, a**5*b**4, a**5*b**5, a**5*b**6, a**5*b**7],\n", + "[a**6, a**6*b, a**6*b**2, a**6*b**3, a**6*b**4, a**6*b**5, a**6*b**6, a**6*b**7],\n", + "[a**7, a**7*b, a**7*b**2, a**7*b**3, a**7*b**4, a**7*b**5, a**7*b**6, a**7*b**7]])" ] }, "metadata": {}, @@ -203,10 +206,10 @@ { "data": { "text/latex": [ - "$\\displaystyle \\left[\\begin{array}{ccccccccccccccccccccccccc}1 & b & b^{2} & b^{3} & b^{4} & a & a b & a b^{2} & a b^{3} & a b^{4} & a^{2} & a^{2} b & a^{2} b^{2} & a^{2} b^{3} & a^{2} b^{4} & a^{3} & a^{3} b & a^{3} b^{2} & a^{3} b^{3} & a^{3} b^{4} & a^{4} & a^{4} b & a^{4} b^{2} & a^{4} b^{3} & a^{4} b^{4}\\end{array}\\right]$" + "$\\displaystyle \\left[\\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}1 & b & b^{2} & b^{3} & b^{4} & b^{5} & b^{6} & b^{7} & a & a b & a b^{2} & a b^{3} & a b^{4} & a b^{5} & a b^{6} & a b^{7} & a^{2} & a^{2} b & a^{2} b^{2} & a^{2} b^{3} & a^{2} b^{4} & a^{2} b^{5} & a^{2} b^{6} & a^{2} b^{7} & a^{3} & a^{3} b & a^{3} b^{2} & a^{3} b^{3} & a^{3} b^{4} & a^{3} b^{5} & a^{3} b^{6} & a^{3} b^{7} & a^{4} & a^{4} b & a^{4} b^{2} & a^{4} b^{3} & a^{4} b^{4} & a^{4} b^{5} & a^{4} b^{6} & a^{4} b^{7} & a^{5} & a^{5} b & a^{5} b^{2} & a^{5} b^{3} & a^{5} b^{4} & a^{5} b^{5} & a^{5} b^{6} & a^{5} b^{7} & a^{6} & a^{6} b & a^{6} b^{2} & a^{6} b^{3} & a^{6} b^{4} & a^{6} b^{5} & a^{6} b^{6} & a^{6} b^{7} & a^{7} & a^{7} b & a^{7} b^{2} & a^{7} b^{3} & a^{7} b^{4} & a^{7} b^{5} & a^{7} b^{6} & a^{7} b^{7}\\end{array}\\right]$" ], "text/plain": [ - "Matrix([[1, b, b**2, b**3, b**4, a, a*b, a*b**2, a*b**3, a*b**4, a**2, a**2*b, a**2*b**2, a**2*b**3, a**2*b**4, a**3, a**3*b, a**3*b**2, a**3*b**3, a**3*b**4, a**4, a**4*b, a**4*b**2, a**4*b**3, a**4*b**4]])" + "Matrix([[1, b, b**2, b**3, b**4, b**5, b**6, b**7, a, a*b, a*b**2, a*b**3, a*b**4, a*b**5, a*b**6, a*b**7, a**2, a**2*b, a**2*b**2, a**2*b**3, a**2*b**4, a**2*b**5, a**2*b**6, a**2*b**7, a**3, a**3*b, a**3*b**2, a**3*b**3, a**3*b**4, a**3*b**5, a**3*b**6, a**3*b**7, a**4, a**4*b, a**4*b**2, a**4*b**3, a**4*b**4, a**4*b**5, a**4*b**6, a**4*b**7, a**5, a**5*b, a**5*b**2, a**5*b**3, a**5*b**4, a**5*b**5, a**5*b**6, a**5*b**7, a**6, a**6*b, a**6*b**2, a**6*b**3, a**6*b**4, a**6*b**5, a**6*b**6, a**6*b**7, a**7, a**7*b, a**7*b**2, a**7*b**3, a**7*b**4, a**7*b**5, a**7*b**6, a**7*b**7]])" ] }, "metadata": {}, @@ -224,6 +227,15 @@ "display(all_monomials)\n" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## get_coeffs\n", + "\n", + "A function to get the coefficients from a polynomial, in the order defined by monomials" + ] + }, { "cell_type": "code", "execution_count": 5, @@ -232,11 +244,14 @@ { "data": { "text/plain": [ - "array([[0, 0, 0, 0, 0],\n", - " [0, 0, 0, 0, 0],\n", - " [0, 0, 0, 0, 225],\n", - " [0, 0, 0, 400, 0],\n", - " [0, 0, 225, 0, 0]], dtype=object)" + "array([[0, 0, 0, 0, 0, 0, 1, 0],\n", + " [0, 0, 0, 0, 0, 36, 0, 0],\n", + " [0, 0, 0, 0, 225, 0, 0, 0],\n", + " [0, 0, 0, 400, 0, 0, 0, 0],\n", + " [0, 0, 225, 0, 0, 0, 0, 0],\n", + " [0, 36, 0, 0, 0, 0, 0, 0],\n", + " [1, 0, 0, 0, 0, 0, 0, 0],\n", + " [0, 0, 0, 0, 0, 0, 0, 0]], dtype=object)" ] }, "execution_count": 5, @@ -251,6 +266,15 @@ "np.array(get_coeffs(binom_factor_sym(6,6,a,b,6))).reshape(LMAX,LMAX)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Build the weight matrix\n", + "\n", + "W[i,j,s] = the polynomial coefficients for binom_factor(i,j,a,b,s)" + ] + }, { "cell_type": "code", "execution_count": 6, @@ -260,15 +284,26 @@ "name": "stdout", "output_type": "stream", "text": [ - "(0, 1, 2) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(0, a, b, domain='ZZ')\n", - "(0, 1, 4) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(0, a, b, domain='ZZ')\n", - "(0, 3, 3) (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(1, a, b, domain='ZZ')\n", - "(1, 0, 4) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(0, a, b, domain='ZZ')\n", - "(2, 1, 3) (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(1, a, b, domain='ZZ')\n", - "(3, 0, 4) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(0, a, b, domain='ZZ')\n", - "(3, 1, 1) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(a**3 + 3*a**2*b, a, b, domain='ZZ')\n", - "(3, 4, 0) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0) Poly(a**3*b**4, a, b, domain='ZZ')\n", - "(4, 2, 0) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0) Poly(a**4*b**2, a, b, domain='ZZ')\n"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, 0, 0, 0, 100, 0, 0, 0, 0, 0, 0, 150, 0, 0, 0, 0, 0, 0, 60, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(5*a**6*b + 60*a**5*b**2 + 150*a**4*b**3 + 100*a**3*b**4 + 15*a**2*b**5, a, b, domain='ZZ')\n", + "(6, 6, 7) (0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 300, 0, 0, 0, 0, 0, 0, 300, 0, 0, 0, 0, 0, 0, 90, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(6*a**5 + 90*a**4*b + 300*a**3*b**2 + 300*a**2*b**3 + 90*a*b**4 + 6*b**5, a, b, domain='ZZ')\n", + "(7, 2, 4) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(21*a**5 + 70*a**4*b + 35*a**3*b**2, a, b, domain='ZZ')\n", + "(7, 2, 7) (0, 0, 1, 0, 0, 0, 0, 0, 0, 14, 0, 0, 0, 0, 0, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) Poly(21*a**2 + 14*a*b + b**2, a, b, domain='ZZ')\n", + "(7, 6, 4) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 210, 0, 0, 0, 0, 0, 0, 315, 0, 0, 0, 0, 0, 0, 140, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0) Poly(15*a**7*b**2 + 140*a**6*b**3 + 315*a**5*b**4 + 210*a**4*b**5 + 35*a**3*b**6, a, b, domain='ZZ')\n", + "(7, 6, 6) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 126, 0, 0, 0, 0, 0, 0, 525, 0, 0, 0, 0, 0, 0, 700, 0, 0, 0, 0, 0, 0, 315, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0) Poly(a**7 + 42*a**6*b + 315*a**5*b**2 + 700*a**4*b**3 + 525*a**3*b**4 + 126*a**2*b**5 + 7*a*b**6, a, b, domain='ZZ')\n", + "(7, 7, 3) (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0, 0, 0, 0, 147, 0, 0, 0, 0, 0, 0, 147, 0, 0, 0, 0, 0, 0, 35, 0, 0, 0) Poly(35*a**7*b**4 + 147*a**6*b**5 + 147*a**5*b**6 + 35*a**4*b**7, a, b, domain='ZZ')\n" ] } ], @@ -284,6 +319,13 @@ " weights[i, j, s, :] = val" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## How sparse?" + ] + }, { "cell_type": "code", "execution_count": 7, @@ -293,16 +335,67 @@ "name": "stdout", "output_type": "stream", "text": [ - "[ 1. 2.33 5.4289 12.649336 29.472952 1.1\n", - " 2.563 5.97179 13.914269 32.420246 1.21 2.8193\n", - " 6.568969 15.3056965 35.662273 1.3310001 3.1012301 7.225866\n", - " 16.836267 39.2285 1.4641001 3.411353 7.948453 18.519894\n", - " 43.151352 ]\n", - "[ 1. 2.32999992 5.42889977 12.64933576 29.47295135 1.10000002\n", - " 2.56299996 5.97178984 13.91426963 32.42024719 1.21000004 2.81929994\n", - " 6.56896877 15.30569675 35.66227226 1.33100009 3.1012301 7.22586606\n", - " 16.83626699 39.2285008 1.46410013 3.41135318 7.94845284 18.51989409\n", - " 43.15135181]\n" + "nnz=1086\n", + "elementwise sparsity = 97%\n", + "all-zero = 16%\n" + ] + } + ], + "source": [ + "nnz = len(np.nonzero(weights)[0])\n", + "print(f'nnz={nnz}')\n", + "\n", + "sparsity = 1 - nnz/LMAX**5\n", + "print(f'elementwise sparsity = {sparsity*100:.0f}%')\n", + "\n", + "all_zero_fraction = 1 - len(np.nonzero(np.sum(abs(weights), axis=3))[0]) / LMAX**3\n", + "print(f'all-zero = {all_zero_fraction*100:.0f}%')" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## get_monomials(a,b)\n", + "\n", + "Given float values a,b compute the monomials as above. This function will be exported to `binom_factor_table.py`. \n", + "\n", + "We test it here by running on a sample input" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 1. 2.33 5.4289 12.649336 29.472952 68.671974\n", + " 160.00569 372.81326 1.1 2.563 5.97179 13.914269\n", + " 32.420246 75.53918 176.00627 410.0946 1.21 2.8193\n", + " 6.568969 15.3056965 35.662273 83.093094 193.60689 451.10406\n", + " 1.3310001 3.1012301 7.225866 16.836267 39.2285 91.402405\n", + " 212.96759 496.21448 1.4641001 3.411353 7.948453 18.519894\n", + " 43.151352 100.54265 234.26436 545.83594 1.6105102 3.7524886\n", + " 8.743299 20.371885 47.46649 110.59692 257.6908 600.41956\n", + " 1.7715613 4.1277375 9.617628 22.409073 52.21314 121.65661\n", + " 283.4599 660.46155 1.9487174 4.540511 10.5793915 24.64998\n", + " 57.434452 133.82227 311.80588 726.5077 ]\n", + "[ 1. 2.32999992 5.42889977 12.64933576 29.47295135\n", + " 68.6719744 160.0056951 372.81325738 1.10000002 2.56299996\n", + " 5.97178984 13.91426963 32.42024719 75.53917347 176.00626843\n", + " 410.09459201 1.21000004 2.81929994 6.56896877 15.30569675\n", + " 35.66227226 83.09309164 193.60689718 451.10405566 1.33100009\n", + " 3.1012301 7.22586606 16.83626699 39.2285008 91.40240386\n", + " 212.96759403 496.21447784 1.46410013 3.41135318 7.94845284\n", + " 18.51989409 43.15135181 100.54264643 234.26435851 545.83593746\n", + " 1.61051017 3.75248858 8.74329831 20.37188394 47.46648802\n", + " 110.59691347 257.69079995 600.41954422 1.77156123 4.12773753\n", + " 9.61762835 22.40907282 52.21313796 121.65660745 283.45988609\n", + " 660.46151296 1.9487174 4.54051138 10.57939141 24.64998063\n", + " 57.434453 133.8222711 311.80588145 726.50768 ]\n" ] } ], @@ -327,21 +420,11 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "nnz=190\n" - ] - } - ], + "outputs": [], "source": [ "inds = np.nonzero(weights)\n", - "print(f'nnz={len(inds[0])}')\n", - "\n", "import inspect\n", "\n", "with np.printoptions(threshold=np.inf, formatter={'float':lambda x:f'{x:.10g}'}):\n", @@ -386,33 +469,78 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "monomials=DeviceArray([ 1. , 2.2 , 4.84 , 10.648001 , 23.425602 ,\n", - " 1.1 , 2.42 , 5.3240004, 11.712801 , 25.768162 ,\n", - " 1.21 , 2.6620002, 5.8564005, 12.884081 , 28.344978 ,\n", - " 1.3310001, 2.9282002, 6.4420404, 14.17249 , 31.179478 ,\n", - " 1.4641001, 3.2210202, 7.0862446, 15.589739 , 34.29743 ], dtype=float32)\n", - "(0, 3, 3) 1.0 [1.]\n", - "(0, 4, 2) 29.040000915527344 [29.04]\n", - "(1, 0, 2) 0 [0.]\n", - "(1, 0, 3) 0 [0.]\n", - "(2, 0, 1) 2.200000047683716 [2.2]\n", + "monomials=DeviceArray([ 1. , 2.2 , 4.84 , 10.648001 ,\n", + " 23.425602 , 51.536327 , 113.37992 , 249.43582 ,\n", + " 1.1 , 2.42 , 5.3240004, 11.712801 ,\n", + " 25.768162 , 56.68996 , 124.71792 , 274.3794 ,\n", + " 1.21 , 2.6620002, 5.8564005, 12.884081 ,\n", + " 28.344978 , 62.35896 , 137.18971 , 301.81735 ,\n", + " 1.3310001, 2.9282002, 6.4420404, 14.17249 ,\n", + " 31.179478 , 68.59486 , 150.90869 , 331.9991 ,\n", + " 1.4641001, 3.2210202, 7.0862446, 15.589739 ,\n", + " 34.29743 , 75.454346 , 165.99956 , 365.199 ,\n", + " 1.6105102, 3.5431225, 7.79487 , 17.148714 ,\n", + " 37.727173 , 82.99978 , 182.59952 , 401.71893 ,\n", + " 1.7715613, 3.897435 , 8.574357 , 18.863586 ,\n", + " 41.49989 , 91.29976 , 200.85948 , 441.89084 ,\n", + " 1.9487174, 4.287178 , 9.431792 , 20.749945 ,\n", + " 45.649876 , 100.42973 , 220.94542 , 486.07993 ], dtype=float32)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(0, 0, 0) 1.0 [1.]\n", + "(0, 0, 5) 0 [0.]\n", + "(0, 0, 6) 0 [0.]\n", + "(0, 1, 2) 0 [0.]\n", + "(1, 1, 3) 0 [0.]\n", + "(1, 1, 6) 0 [0.]\n", + "(1, 3, 5) 0 [0.]\n", + "(1, 4, 3) 38.72000133514405 [38.72]\n", + "(1, 4, 5) 1.0 [1.]\n", + "(1, 6, 7) 1.0 [1.]\n", "(2, 1, 4) 0 [0.]\n", - "(2, 3, 0) 12.88408124395375 [12.884081]\n", - "(2, 3, 2) 50.578002816677134 [50.578003]\n", - "(2, 4, 0) 28.344979351059116 [28.344978]\n", - "(3, 1, 2) 10.890000429153446 [10.89]\n", - "(3, 1, 3) 5.5000001192092896 [5.5]\n", + "(2, 2, 0) 5.856400369262701 [5.8564005]\n", + "(2, 3, 3) 30.2500011253357 [30.25]\n", + "(2, 3, 6) 0 [0.]\n", + "(2, 5, 2) 438.05876595012853 [438.05878]\n", + "(3, 2, 5) 1.0 [1.]\n", + "(3, 3, 0) 14.172489843082529 [14.17249]\n", + "(3, 4, 4) 171.69900965380683 [171.699]\n", + "(3, 4, 5) 61.71000228881837 [61.710003]\n", + "(3, 4, 6) 12.100000262260437 [12.1]\n", + "(3, 5, 1) 342.9742594246647 [342.97427]\n", + "(3, 6, 3) 2692.773055105913 [2692.773]\n", + "(3, 7, 2) 5144.614001991794 [5144.6143]\n", + "(4, 0, 6) 0 [0.]\n", + "(4, 0, 7) 0 [0.]\n", "(4, 2, 2) 60.02810437345515 [60.028107]\n", - "(4, 2, 4) 31.460001220703134 [31.460001]\n", - "(4, 3, 2) 164.27203597465098 [164.27203]\n", - "(4, 3, 4) 127.77600698661814 [127.776]\n" + "(4, 2, 6) 1.0 [1.]\n", + "(4, 3, 0) 15.58973916528927 [15.589739]\n", + "(4, 5, 4) 1613.731182697727 [1613.7311]\n", + "(4, 7, 6) 7959.14124416379 [7959.1416]\n", + "(5, 0, 4) 5.5000001192092896 [5.5]\n", + "(5, 0, 6) 0 [0.]\n", + "(5, 3, 2) 258.64793837960883 [258.64795]\n", + "(5, 5, 0) 82.99977671291498 [82.99978]\n", + "(5, 6, 0) 182.5995127261507 [182.59952]\n", + "(6, 1, 1) 23.030295995009112 [23.030296]\n", + "(6, 3, 5) 531.4683398457538 [531.4683]\n", + "(6, 6, 3) 13581.78134955436 [13581.781]\n", + "(6, 6, 4) 20192.610065654717 [20192.611]\n", + "(6, 6, 6) 15924.563805685058 [15924.564]\n", + "(7, 0, 5) 25.410000801086426 [25.41]\n", + "(7, 2, 4) 484.76355986921754 [484.76355]\n", + "(7, 3, 4) 1475.7104961144375 [1475.7103]\n" ] } ], @@ -435,13 +563,6 @@ " print((i, j, s), bf, table_ab[i, j, s])\n", " np.testing.assert_allclose(bf, table_ab[i, j, s], rtol=1e-6)" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": {