From 9bf28e3edd5310d29582de8aa18e697b42b802a2 Mon Sep 17 00:00:00 2001 From: NT Date: Sun, 4 Apr 2021 13:48:21 +0800 Subject: [PATCH] updates for latex build --- diffphys-code-sol.ipynb | 24 +++++++++--------------- make-pdf.sh | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 make-pdf.sh diff --git a/diffphys-code-sol.ipynb b/diffphys-code-sol.ipynb index 802873d..6be162b 100644 --- a/diffphys-code-sol.ipynb +++ b/diffphys-code-sol.ipynb @@ -18,10 +18,10 @@ "\n", "In order to learn the error function, we'll consider two different discretizations of the same PDE $\\mathcal P^*$: \n", "a _reference_ version, which we assume to be accurate, with a discretized version \n", - "$\\mathcal P_r$, and solutions $\\mathbf r \\in \\mathscr R$, where $\\mathscr R$ denotes the manifold of solution of $\\mathcal P_r$.\n", + "$\\mathcal P_r$, and solutions $\\mathbf r \\in \\mathscr R$, where $\\mathscr R$ denotes the manifold of solutions of $\\mathcal P_r$.\n", "In parallel to this, we have a less accurate approximation of the same PDE, which we'll refer to as the _source_ version, as this will be the solver that our NN should later on interact with. Analogously,\n", "we have $\\mathcal P_s$ with solutions $\\mathbf s \\in \\mathscr S$.\n", - "And after training, we'll have a _hybrid_ solver that uses $\\mathcal P_s$ in conjunction with a trained network to obtain improved solutions, i.e., solutions that are closer to the ones produced by $\\mathcal P_r$.\n", + "After training, we'll obtain a _hybrid_ solver that uses $\\mathcal P_s$ in conjunction with a trained network to obtain improved solutions, i.e., solutions that are closer to the ones produced by $\\mathcal P_r$.\n", "\n", "```{figure} resources/diffphys-sol-manifolds.jpeg\n", "---\n", @@ -39,7 +39,6 @@ }, "source": [ "\n", - "explain coarse/ref setup...\n", "Let's assume $\\mathcal{P}$ advances a solution by a time step $\\Delta t$, and let's denote $n$ consecutive steps by a superscript:\n", "$\n", "\\newcommand{\\pde}{\\mathcal{P}}\n", @@ -48,7 +47,7 @@ "\\newcommand{\\vr}[1]{\\mathbf{r}_{#1}} \n", "\\newcommand{\\vcN}{\\vs} \n", "\\newcommand{\\project}{\\mathcal{T}} \n", - "\\vc{t+n} = \\pdec(\\pdec(\\cdots \\pdec( \\project \\vr{t} )\\cdots)) = \\pdec^n ( \\project \\vr{t} ) .\n", + "\\vc{t+n} = \\pdec(\\pdec(\\cdots \\pdec( \\mathcal{T} \\vr{t} )\\cdots)) = \\pdec^n ( \\mathcal{T} \\vr{t} ) .\n", "$\n", "Here we assume a mapping operator $\\mathcal{T}$ exists that transfers a reference solution to the source manifold. This could, e.g., be a simple downsampling operation.\n", "Especially for longer sequences, i.e. larger $n$, the source state \n", @@ -62,17 +61,14 @@ "\\newcommand{\\corr}{\\mathcal{C}} \n", "\\newcommand{\\vc}[1]{\\mathbf{s}_{#1}} \n", "\\newcommand{\\vr}[1]{\\mathbf{r}_{#1}} \n", - "\\loss (\\vc{t},\\project \\vr{t})=\\Vert\\vc{t}-\\project \\vr{t}\\Vert_2$. \n", + "\\loss (\\vc{t},\\mathcal{T} \\vr{t})=\\Vert\\vc{t}-\\mathcal{T} \\vr{t}\\Vert_2$. \n", "Our learning goal is to train at a correction operator \n", - "$\\newcommand{\\corr}{\\mathcal{C}} \n", - "\\corr ( \\vc{} )$ such that \n", + "$\\mathcal{C} ( \\mathbf{s} )$ such that \n", "a solution to which the correction is applied has a lower error than the original unmodified (source) \n", "solution: $\\newcommand{\\loss}{e} \n", - "\\newcommand{\\pdec}{\\pde_{s}}\n", "\\newcommand{\\corr}{\\mathcal{C}} \n", - "\\newcommand{\\project}{\\mathcal{T}} \n", "\\newcommand{\\vr}[1]{\\mathbf{r}_{#1}} \n", - "\\loss ( \\pdec( \\corr (\\project \\vr{t_0}) ) , \\project \\vr{t_1}) < \\loss ( \\pdec( \\project \\vr{t_0} ), \\project \\vr{t_1})$. \n", + "\\loss ( \\mathcal{P}_{s}( \\corr (\\mathcal{T} \\vr{t_0}) ) , \\mathcal{T} \\vr{t_1}) < \\loss ( \\mathcal{P}_{s}( \\mathcal{T} \\vr{t_0} ), \\mathcal{T} \\vr{t_1})$. \n", "\n", "The correction function \n", "$\\newcommand{\\vcN}{\\mathbf{s}} \\newcommand{\\corr}{\\mathcal{C}} \\corr (\\vcN | \\theta)$ \n", @@ -82,11 +78,9 @@ "The overall learning goal now becomes\n", "\n", "$\n", - "\\newcommand{\\pdec}{\\pde_{s}}\n", - "\\newcommand{\\corr}{\\mathcal{C}} \n", - "\\newcommand{\\project}{\\mathcal{T}} \n", + "\\newcommand{\\corr}{\\mathcal{C}} \n", "\\newcommand{\\vr}[1]{\\mathbf{r}_{#1}} \n", - "\\text{argmin}_\\theta | ( \\pdec \\corr )^n ( \\project \\vr{t} ) - \\project \\vr{t}|^2\n", + "\\text{argmin}_\\theta | ( \\mathcal{P}_{s} \\corr )^n ( \\mathcal{T} \\vr{t} ) - \\mathcal{T} \\vr{t}|^2\n", "$\n", "\n", "A crucial bit here that's easy to overlook is that the correction depends on the modified states, i.e.\n", @@ -96,7 +90,7 @@ "These states actually evolve over time when training. They don't exist beforehand.\n", "\n", "**TL;DR**:\n", - "We'll train a network $\\mathcal{C}$ to reduce the numerical errors of a simulator with a more accurate reference. Here it's crucial to have the _source_ solver realized as a differential physics operator, such that it can give gradients for an improved training of $\\mathcal{C}$.\n", + "We'll train a network $\\mathcal{C}$ to reduce the numerical errors of a simulator with a more accurate reference. It's crucial to have the _source_ solver realized as a differential physics operator, such that it can give gradients for an improved training of $\\mathcal{C}$.\n", "\n", "
\n", "\n", diff --git a/make-pdf.sh b/make-pdf.sh new file mode 100644 index 0000000..cf287a4 --- /dev/null +++ b/make-pdf.sh @@ -0,0 +1,37 @@ +# source this file with "." in a shell + +echo +echo Note: manually quit first latex pass with shift-x +echo + +cd /Users/thuerey/Dropbox/mbaDevelSelected/pbdl-book/ +/Users/thuerey/Library/Python/3.7/bin/jupyter-book build . --builder pdflatex + +cd /Users/thuerey/Dropbox/mbaDevelSelected/pbdl-book/_build/latex +export JPYFILENAME=book.tex +rm ${JPYFILENAME}-in.bak +mv ${JPYFILENAME} ${JPYFILENAME}-in.bak +iconv -c -f utf-8 -t ascii ${JPYFILENAME}-in.bak > ${JPYFILENAME} + +echo running SED +sed -i '' -e 's/sphinxincludegraphics{{/sphinxincludegraphics{/g' ${JPYFILENAME} +sed -i '' -e 's/}.png}/.png}/g' ${JPYFILENAME} +sed -i '' -e 's/}.jpg}/.jpg}/g' ${JPYFILENAME} +sed -i '' -e 's/}.jpeg}/.jpeg}/g' ${JPYFILENAME} +sed -i '' -e 's/sphinxpxdimen]{{/sphinxpxdimen]{/g' ${JPYFILENAME} + +# ugly, -i doesnt work here: +sed '28i\ +\\usepackage{mathrsfs} ' ${JPYFILENAME} > tmp-latex +echo renaming: tmp-latex ${JPYFILENAME}; ls -l tmp-latex ${JPYFILENAME} +rm ${JPYFILENAME} +mv tmp-latex ${JPYFILENAME} + +echo running LATEX +pdflatex book + +echo running LATEX , 2nd pass +pdflatex book + +cd ../.. +