diff --git a/explore.ipynb b/explore.ipynb deleted file mode 100644 index 24318c4..0000000 --- a/explore.ipynb +++ /dev/null @@ -1,164 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import sympy as sym\n", - "from sympy import *\n", - "\n", - "def symbolize_matrix(matrix_prefix=\"k\"):\n", - " \"\"\"Symbolize a matrix with the given prefix.\n", - " \n", - " Parameters\n", - " ----------\n", - " matrix_prefix : str\n", - " The prefix to use for the matrix.\n", - " \n", - " Returns\n", - " -------\n", - " A : sympy.Matrix\n", - " The symbolized matrix.\n", - " \"\"\"\n", - " A = sym.Matrix([\n", - " [sym.symbols(f\"{matrix_prefix}_00\"), sym.symbols(f\"{matrix_prefix}_01\"), sym.symbols(f\"{matrix_prefix}_02\")],\n", - " [sym.symbols(f\"{matrix_prefix}_10\"), sym.symbols(f\"{matrix_prefix}_11\"), sym.symbols(f\"{matrix_prefix}_12\")],\n", - " [sym.symbols(f\"{matrix_prefix}_20\"), sym.symbols(f\"{matrix_prefix}_21\"), sym.symbols(f\"{matrix_prefix}_22\")]\n", - " ])\n", - " return A\n", - "\n", - "A = symbolize_matrix(\"a\")\n", - "\n", - "B=A*(A.T)\n", - "\n", - "DB = symbolize_matrix(\"\\partial_B\")\n", - "# sum(diff(B[i,j], A[0,0]) for i in range(3) for j in range(3))\n", - "DB = sym.Matrix([\n", - " [diff(B[0,0], A[0,0]), diff(B[0,0], A[0,1]), diff(B[0,0], A[0,2]), diff(B[0,0], A[1,0]), diff(B[0,0], A[1,1]), diff(B[0,0], A[1,2]), diff(B[0,0], A[2,0]), diff(B[0,0], A[2,1]), diff(B[0,0], A[2,2])],\n", - " [diff(B[0,1], A[0,0]), diff(B[0,1], A[0,1]), diff(B[0,1], A[0,2]), diff(B[0,1], A[1,0]), diff(B[0,1], A[1,1]), diff(B[0,1], A[1,2]), diff(B[0,1], A[2,0]), diff(B[0,1], A[2,1]), diff(B[0,1], A[2,2])],\n", - " [diff(B[0,2], A[0,0]), diff(B[0,2], A[0,1]), diff(B[0,2], A[0,2]), diff(B[0,2], A[1,0]), diff(B[0,2], A[1,1]), diff(B[0,2], A[1,2]), diff(B[0,2], A[2,0]), diff(B[0,2], A[2,1]), diff(B[0,2], A[2,2])],\n", - " [diff(B[1,0], A[0,0]), diff(B[1,0], A[0,1]), diff(B[1,0], A[0,2]), diff(B[1,0], A[1,0]), diff(B[1,0], A[1,1]), diff(B[1,0], A[1,2]), diff(B[1,0], A[2,0]), diff(B[1,0], A[2,1]), diff(B[1,0], A[2,2])],\n", - " [diff(B[1,1], A[0,0]), diff(B[1,1], A[0,1]), diff(B[1,1], A[0,2]), diff(B[1,1], A[1,0]), diff(B[1,1], A[1,1]), diff(B[1,1], A[1,2]), diff(B[1,1], A[2,0]), diff(B[1,1], A[2,1]), diff(B[1,1], A[2,2])],\n", - " [diff(B[1,2], A[0,0]), diff(B[1,2], A[0,1]), diff(B[1,2], A[0,2]), diff(B[1,2], A[1,0]), diff(B[1,2], A[1,1]), diff(B[1,2], A[1,2]), diff(B[1,2], A[2,0]), diff(B[1,2], A[2,1]), diff(B[1,2], A[2,2])],\n", - " [diff(B[2,0], A[0,0]), diff(B[2,0], A[0,1]), diff(B[2,0], A[0,2]), diff(B[2,0], A[1,0]), diff(B[2,0], A[1,1]), diff(B[2,0], A[1,2]), diff(B[2,0], A[2,0]), diff(B[2,0], A[2,1]), diff(B[2,0], A[2,2])],\n", - " [diff(B[2,1], A[0,0]), diff(B[2,1], A[0,1]), diff(B[2,1], A[0,2]), diff(B[2,1], A[1,0]), diff(B[2,1], A[1,1]), diff(B[2,1], A[1,2]), diff(B[2,1], A[2,0]), diff(B[2,1], A[2,1]), diff(B[2,1], A[2,2])],\n", - " [diff(B[2,2], A[0,0]), diff(B[2,2], A[0,1]), diff(B[2,2], A[0,2]), diff(B[2,2], A[1,0]), diff(B[2,2], A[1,1]), diff(B[2,2], A[1,2]), diff(B[2,2], A[2,0]), diff(B[2,2], A[2,1]), diff(B[2,2], A[2,2])]\n", - "])\n", - "print(DB)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": {}, - "outputs": [ - { - "data": { - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}2 a_{00} k_{00} + a_{01} k_{01} + a_{01} k_{10} + a_{02} k_{02} + a_{02} k_{20} & a_{00} k_{01} + a_{00} k_{10} + 2 a_{01} k_{11} + a_{02} k_{12} + a_{02} k_{21} & 0 & 0\\\\a_{10} k_{00} + a_{11} k_{01} + a_{12} k_{02} & a_{10} k_{10} + a_{11} k_{11} + a_{12} k_{12} & a_{00} k_{00} + a_{01} k_{10} + a_{02} k_{20} & a_{00} k_{01} + a_{01} k_{11} + a_{02} k_{21}\\\\a_{10} k_{00} + a_{11} k_{10} + a_{12} k_{20} & a_{10} k_{01} + a_{11} k_{11} + a_{12} k_{21} & a_{00} k_{00} + a_{01} k_{01} + a_{02} k_{02} & a_{00} k_{10} + a_{01} k_{11} + a_{02} k_{12}\\\\0 & 0 & 2 a_{10} k_{00} + a_{11} k_{01} + a_{11} k_{10} + a_{12} k_{02} + a_{12} k_{20} & a_{10} k_{01} + a_{10} k_{10} + 2 a_{11} k_{11} + a_{12} k_{12} + a_{12} k_{21}\\end{matrix}\\right]$" - ], - "text/plain": [ - "Matrix([\n", - "[2*a_00*k_00 + a_01*k_01 + a_01*k_10 + a_02*k_02 + a_02*k_20, a_00*k_01 + a_00*k_10 + 2*a_01*k_11 + a_02*k_12 + a_02*k_21, 0, 0],\n", - "[ a_10*k_00 + a_11*k_01 + a_12*k_02, a_10*k_10 + a_11*k_11 + a_12*k_12, a_00*k_00 + a_01*k_10 + a_02*k_20, a_00*k_01 + a_01*k_11 + a_02*k_21],\n", - "[ a_10*k_00 + a_11*k_10 + a_12*k_20, a_10*k_01 + a_11*k_11 + a_12*k_21, a_00*k_00 + a_01*k_01 + a_02*k_02, a_00*k_10 + a_01*k_11 + a_02*k_12],\n", - "[ 0, 0, 2*a_10*k_00 + a_11*k_01 + a_11*k_10 + a_12*k_02 + a_12*k_20, a_10*k_01 + a_10*k_10 + 2*a_11*k_11 + a_12*k_12 + a_12*k_21]])" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "DB = symbolize_matrix(\"\\partial_B\")\n", - "# sum(diff(B[i,j], A[0,0]) for i in range(3) for j in range(3))\n", - "DB = sym.Matrix([\n", - " [diff(B[0,0], A[0,0]), diff(B[0,0], A[0,1]), diff(B[0,0], A[0,2]), diff(B[0,0], A[1,0]), diff(B[0,0], A[1,1]), diff(B[0,0], A[1,2]), diff(B[0,0], A[2,0]), diff(B[0,0], A[2,1]), diff(B[0,0], A[2,2])],\n", - " [diff(B[0,1], A[0,0]), diff(B[0,1], A[0,1]), diff(B[0,1], A[0,2]), diff(B[0,1], A[1,0]), diff(B[0,1], A[1,1]), diff(B[0,1], A[1,2]), diff(B[0,1], A[2,0]), diff(B[0,1], A[2,1]), diff(B[0,1], A[2,2])],\n", - " [diff(B[0,2], A[0,0]), diff(B[0,2], A[0,1]), diff(B[0,2], A[0,2]), diff(B[0,2], A[1,0]), diff(B[0,2], A[1,1]), diff(B[0,2], A[1,2]), diff(B[0,2], A[2,0]), diff(B[0,2], A[2,1]), diff(B[0,2], A[2,2])],\n", - " [diff(B[1,0], A[0,0]), diff(B[1,0], A[0,1]), diff(B[1,0], A[0,2]), diff(B[1,0], A[1,0]), diff(B[1,0], A[1,1]), diff(B[1,0], A[1,2]), diff(B[1,0], A[2,0]), diff(B[1,0], A[2,1]), diff(B[1,0], A[2,2])],\n", - " [diff(B[1,1], A[0,0]), diff(B[1,1], A[0,1]), diff(B[1,1], A[0,2]), diff(B[1,1], A[1,0]), diff(B[1,1], A[1,1]), diff(B[1,1], A[1,2]), diff(B[1,1], A[2,0]), diff(B[1,1], A[2,1]), diff(B[1,1], A[2,2])],\n", - " [diff(B[1,2], A[0,0]), diff(B[1,2], A[0,1]), diff(B[1,2], A[0,2]), diff(B[1,2], A[1,0]), diff(B[1,2], A[1,1]), diff(B[1,2], A[1,2]), diff(B[1,2], A[2,0]), diff(B[1,2], A[2,1]), diff(B[1,2], A[2,2])],\n", - " [diff(B[2,0], A[0,0]), diff(B[2,0], A[0,1]), diff(B[2,0], A[0,2]), diff(B[2,0], A[1,0]), diff(B[2,0], A[1,1]), diff(B[2,0], A[1,2]), diff(B[2,0], A[2,0]), diff(B[2,0], A[2,1]), diff(B[2,0], A[2,2])],\n", - " [diff(B[2,1], A[0,0]), diff(B[2,1], A[0,1]), diff(B[2,1], A[0,2]), diff(B[2,1], A[1,0]), diff(B[2,1], A[1,1]), diff(B[2,1], A[1,2]), diff(B[2,1], A[2,0]), diff(B[2,1], A[2,1]), diff(B[2,1], A[2,2])],\n", - " [diff(B[2,2], A[0,0]), diff(B[2,2], A[0,1]), diff(B[2,2], A[0,2]), diff(B[2,2], A[1,0]), diff(B[2,2], A[1,1]), diff(B[2,2], A[1,2]), diff(B[2,2], A[2,0]), diff(B[2,2], A[2,1]), diff(B[2,2], A[2,2])]\n", - "])\n", - "DB" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": {}, - "outputs": [ - { - "data": { - "text/latex": [ - "$\\displaystyle \\left[\\begin{matrix}a_{00} \\left(a_{00} k_{00} + a_{01} k_{10}\\right) + a_{01} \\left(a_{00} k_{01} + a_{01} k_{11}\\right) & a_{10} \\left(a_{00} k_{00} + a_{01} k_{10}\\right) + a_{11} \\left(a_{00} k_{01} + a_{01} k_{11}\\right)\\\\a_{00} \\left(a_{10} k_{00} + a_{11} k_{10}\\right) + a_{01} \\left(a_{10} k_{01} + a_{11} k_{11}\\right) & a_{10} \\left(a_{10} k_{00} + a_{11} k_{10}\\right) + a_{11} \\left(a_{10} k_{01} + a_{11} k_{11}\\right)\\end{matrix}\\right]$" - ], - "text/plain": [ - "Matrix([\n", - "[a_00*(a_00*k_00 + a_01*k_10) + a_01*(a_00*k_01 + a_01*k_11), a_10*(a_00*k_00 + a_01*k_10) + a_11*(a_00*k_01 + a_01*k_11)],\n", - "[a_00*(a_10*k_00 + a_11*k_10) + a_01*(a_10*k_01 + a_11*k_11), a_10*(a_10*k_00 + a_11*k_10) + a_11*(a_10*k_01 + a_11*k_11)]])" - ] - }, - "execution_count": 9, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# DA * DB\n" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### B = $AKA^T$ Gradients w.r.t A\n", - "$\\frac{\\partial L}{\\partial B} = \\left( \\partial L/\\partial b_{0,0}, \\partial L/\\partial b_{0,1} \\right)$\n", - "\n", - "$$vec(d(B)) = vec()$$" - ] - }, - { - "attachments": {}, - "cell_type": "markdown", - "metadata": {}, - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "nerfacc", - "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.8.16" - }, - "orig_nbformat": 4 - }, - "nbformat": 4, - "nbformat_minor": 2 -}