update book
This commit is contained in:
@@ -7,8 +7,8 @@
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>15. Solving Differential Equations with Deep Learning — Applied Data Analysis and Machine Learning</title>
|
||||
|
||||
<link href="_static/css/theme.css" rel="stylesheet" />
|
||||
<link href="_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
|
||||
<link href="_static/css/theme.css" rel="stylesheet">
|
||||
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
|
||||
|
||||
|
||||
<link rel="stylesheet"
|
||||
@@ -31,7 +31,7 @@
|
||||
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
|
||||
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
|
||||
|
||||
<link rel="preload" as="script" href="_static/js/index.1c5a1a01449ed65a7b51.js">
|
||||
<link rel="preload" as="script" href="_static/js/index.be7d3bbb2ef33a8344ce.js">
|
||||
|
||||
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
|
||||
<script src="_static/jquery.js"></script>
|
||||
@@ -41,22 +41,24 @@
|
||||
<script src="_static/clipboard.min.js"></script>
|
||||
<script src="_static/copybutton.js"></script>
|
||||
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
|
||||
<script src="_static/sphinx-book-theme.12a9622fbb08dcb3a2a40b2c02b83a57.js"></script>
|
||||
<script async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
|
||||
<script async="async" src="https://unpkg.com/thebe@0.5.1/lib/index.js"></script>
|
||||
<script>
|
||||
const thebe_selector = ".thebe"
|
||||
const thebe_selector_input = "pre"
|
||||
const thebe_selector_output = ".output"
|
||||
</script>
|
||||
<script src="_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
|
||||
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
|
||||
const thebe_selector = ".thebe,.cell"
|
||||
const thebe_selector_input = "pre"
|
||||
const thebe_selector_output = ".output, .cell_output"
|
||||
</script>
|
||||
<script async="async" src="_static/sphinx-thebe.js"></script>
|
||||
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
|
||||
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="next" title="16. Convolutional Neural Networks" href="chapter12.html" />
|
||||
<link rel="prev" title="14. Building a Feed Forward Neural Network" href="chapter10.html" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="docsearch:language" content="en" />
|
||||
<meta name="docsearch:language" content="None">
|
||||
|
||||
|
||||
<!-- Google Analytics -->
|
||||
|
||||
</head>
|
||||
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
|
||||
@@ -91,11 +93,11 @@
|
||||
<ul class="nav bd-sidenav">
|
||||
<li class="toctree-l1">
|
||||
<a class="reference internal" href="intro.html">
|
||||
Applied Data Analysis and Machine Learning, FYS-STK3155/4155 at the University of Oslo, Norway
|
||||
Applied Data Analysis and Machine Learning
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
About the course
|
||||
</span>
|
||||
@@ -117,7 +119,7 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
Review of Statistics with Resampling Techniques and Linear Algebra
|
||||
</span>
|
||||
@@ -134,7 +136,7 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
From Regression to Support Vector Machines
|
||||
</span>
|
||||
@@ -171,7 +173,7 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
Decision Trees, Ensemble Methods and Boosting
|
||||
</span>
|
||||
@@ -188,7 +190,7 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
Dimensionality Reduction
|
||||
</span>
|
||||
@@ -205,7 +207,7 @@
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
<p class="caption" role="heading">
|
||||
<p aria-level="2" class="caption" role="heading">
|
||||
<span class="caption-text">
|
||||
Deep Learning Methods
|
||||
</span>
|
||||
@@ -282,7 +284,7 @@
|
||||
data-placement="left">.ipynb</button></a>
|
||||
<!-- Download PDF via print -->
|
||||
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
|
||||
onClick="window.print()" data-toggle="tooltip" data-placement="left">.pdf</button>
|
||||
onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -300,7 +302,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Table of contents -->
|
||||
<div class="d-none d-md-block col-md-2 bd-toc show">
|
||||
<div class="d-none d-md-block col-md-2 bd-toc show noprint">
|
||||
|
||||
<div class="tocsection onthispage pt-5 pb-3">
|
||||
<i class="fas fa-list"></i> Contents
|
||||
@@ -403,7 +405,113 @@
|
||||
</div>
|
||||
<div id="main-content" class="row">
|
||||
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
|
||||
|
||||
<!-- Table of contents that is only displayed when printing the page -->
|
||||
<div id="jb-print-docs-body" class="onlyprint">
|
||||
<h1>Solving Differential Equations with Deep Learning</h1>
|
||||
<!-- Table of contents -->
|
||||
<div id="print-main-content">
|
||||
<div id="jb-print-toc">
|
||||
|
||||
<div>
|
||||
<h2> Contents </h2>
|
||||
</div>
|
||||
<nav aria-label="Page">
|
||||
<ul class="visible nav section-nav flex-column">
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#example-exponential-decay">
|
||||
15.1. Example: Exponential decay
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#reformulating-the-problem">
|
||||
15.2. Reformulating the problem
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#gradient-descent">
|
||||
15.3. Gradient descent
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#the-code-for-solving-the-ode">
|
||||
15.4. The code for solving the ODE
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#the-network-with-one-input-layer-specified-number-of-hidden-layers-and-one-output-layer">
|
||||
15.5. The network with one input layer, specified number of hidden layers, and one output layer
|
||||
</a>
|
||||
<ul class="nav section-nav flex-column">
|
||||
<li class="toc-h3 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#example-population-growth">
|
||||
15.5.1. Example: Population growth
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#using-forward-euler-to-solve-the-ode">
|
||||
15.6. Using forward Euler to solve the ODE
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#solving-the-one-dimensional-poisson-equation">
|
||||
15.7. Solving the one dimensional Poisson equation
|
||||
</a>
|
||||
<ul class="nav section-nav flex-column">
|
||||
<li class="toc-h3 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#comparing-with-a-numerical-scheme">
|
||||
15.7.1. Comparing with a numerical scheme
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#partial-differential-equations">
|
||||
15.8. Partial Differential Equations
|
||||
</a>
|
||||
<ul class="nav section-nav flex-column">
|
||||
<li class="toc-h3 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#type-of-problem">
|
||||
15.8.1. Type of problem
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h3 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#network-requirements">
|
||||
15.8.2. Network requirements
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#example-the-diffusion-equation">
|
||||
15.9. Example: The diffusion equation
|
||||
</a>
|
||||
<ul class="nav section-nav flex-column">
|
||||
<li class="toc-h3 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#setting-up-the-network-using-autograd-the-full-program">
|
||||
15.9.1. Setting up the network using Autograd; The full program
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#solving-the-wave-equation-with-neural-networks">
|
||||
15.10. Solving the wave equation with Neural Networks
|
||||
</a>
|
||||
</li>
|
||||
<li class="toc-h2 nav-item toc-entry">
|
||||
<a class="reference internal nav-link" href="#resources-on-differential-equations-and-deep-learning">
|
||||
15.11. Resources on differential equations and deep learning
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
</nav>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
|
||||
@@ -1038,8 +1146,8 @@ Max absolute difference: 0.0437499
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 324.246
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Final cost: 0.119936
|
||||
@@ -1264,8 +1372,8 @@ g(t) = \frac{Ag_0}{g_0 + (A - g_0)\exp(-\alpha A t)}
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 0.221805
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Final cost: 0.000417932
|
||||
@@ -1395,8 +1503,8 @@ extending the program that uses the network using Autograd:</p>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 0.221805
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Final cost: 0.000417932
|
||||
@@ -1614,11 +1722,11 @@ g(x) = x(1 - x)\exp(x)
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 457.256
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 457.256
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Final cost: 0.00310113
|
||||
@@ -1907,8 +2015,8 @@ f(x_{N_x - 2})
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 457.256
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Final cost: 0.00310113
|
||||
@@ -2389,189 +2497,168 @@ Using TensorFlow results in a much better execution time. Try it!</p>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cell_output docutils container">
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/MortenImac/anaconda3/lib/python3.8/site-packages/numpy/core/_asarray.py:83: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
|
||||
return array(a, dtype, copy=False, order=order)
|
||||
<div class="output stderr highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>/Users/mhjensen/miniforge3/envs/myenv/lib/python3.9/site-packages/numpy/core/fromnumeric.py:3208: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray.
|
||||
return asarray(a).size
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 41.05505310046362
|
||||
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Initial cost: 41.05505310046363
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="output traceback highlight-ipythontb notranslate"><div class="highlight"><pre><span></span>---------------------------------------------------------------------------
|
||||
KeyboardInterrupt Traceback (most recent call last)
|
||||
/var/folders/jy/g42mrgv128v34gnnhxwk9nrc0000gp/T/ipykernel_47448/73752910.py in <module>
|
||||
<ipython-input-9-fdf8a5d7c717> in <module>
|
||||
141 lmb = 0.01
|
||||
142
|
||||
--> 143 P = solve_pde_deep_neural_network(x,t, num_hidden_neurons, num_iter, lmb)
|
||||
144
|
||||
145 ## Store the results
|
||||
|
||||
/var/folders/jy/g42mrgv128v34gnnhxwk9nrc0000gp/T/ipykernel_47448/73752910.py in solve_pde_deep_neural_network(x, t, num_neurons, num_iter, lmb)
|
||||
<ipython-input-9-fdf8a5d7c717> in solve_pde_deep_neural_network(x, t, num_neurons, num_iter, lmb)
|
||||
118 # Let the update be done num_iter times
|
||||
119 for i in range(num_iter):
|
||||
--> 120 cost_grad = cost_function_grad(P, x , t)
|
||||
121
|
||||
122 for l in range(N_hidden+1):
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
18 else:
|
||||
19 x = tuple(args[i] for i in argnum)
|
||||
---> 20 return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
|
||||
21 return nary_f
|
||||
22 return nary_operator
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/differential_operators.py in grad(fun, x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py in grad(fun, x)
|
||||
23 arguments as `fun`, but returns the gradient instead. The function `fun`
|
||||
24 should be scalar-valued. The gradient has the same type as the argument."""
|
||||
---> 25 vjp, ans = _make_vjp(fun, x)
|
||||
26 if not vspace(ans).size == 1:
|
||||
27 raise TypeError("Grad only applies to real scalar-output functions. "
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in make_vjp(fun, x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py in make_vjp(fun, x)
|
||||
8 def make_vjp(fun, x):
|
||||
9 start_node = VJPNode.new_root()
|
||||
---> 10 end_value, end_node = trace(start_node, fun, x)
|
||||
11 if end_node is None:
|
||||
12 def vjp(g): return vspace(x).zeros()
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/tracer.py in trace(start_node, fun, x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py in trace(start_node, fun, x)
|
||||
8 with trace_stack.new_trace() as t:
|
||||
9 start_box = new_box(x, t, start_node)
|
||||
---> 10 end_box = fun(start_box)
|
||||
11 if isbox(end_box) and end_box._trace == start_box._trace:
|
||||
12 return end_box._value, end_box._node
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/wrap_util.py in unary_f(x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py in unary_f(x)
|
||||
13 else:
|
||||
14 subargs = subvals(args, zip(argnum, x))
|
||||
---> 15 return fun(*subargs, **kwargs)
|
||||
16 if isinstance(argnum, int):
|
||||
17 x = args[argnum]
|
||||
|
||||
/var/folders/jy/g42mrgv128v34gnnhxwk9nrc0000gp/T/ipykernel_47448/73752910.py in cost_function(P, x, t)
|
||||
<ipython-input-9-fdf8a5d7c717> in cost_function(P, x, t)
|
||||
78 g_t = g_trial(point,P)
|
||||
79 g_t_jacobian = g_t_jacobian_func(point,P)
|
||||
---> 80 g_t_hessian = g_t_hessian_func(point,P)
|
||||
81
|
||||
82 g_t_dt = g_t_jacobian[1]
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
18 else:
|
||||
19 x = tuple(args[i] for i in argnum)
|
||||
---> 20 return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
|
||||
21 return nary_f
|
||||
22 return nary_operator
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/differential_operators.py in hessian(fun, x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py in hessian(fun, x)
|
||||
76 def hessian(fun, x):
|
||||
77 "Returns a function that computes the exact Hessian."
|
||||
---> 78 return jacobian(jacobian(fun))(x)
|
||||
79
|
||||
80 @unary_to_nary
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/wrap_util.py in nary_f(*args, **kwargs)
|
||||
18 else:
|
||||
19 x = tuple(args[i] for i in argnum)
|
||||
---> 20 return unary_operator(unary_f, x, *nary_op_args, **nary_op_kwargs)
|
||||
21 return nary_f
|
||||
22 return nary_operator
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/differential_operators.py in jacobian(fun, x)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/differential_operators.py in jacobian(fun, x)
|
||||
59 jacobian_shape = ans_vspace.shape + vspace(x).shape
|
||||
60 grads = map(vjp, ans_vspace.standard_basis())
|
||||
---> 61 return np.reshape(np.stack(grads), jacobian_shape)
|
||||
62
|
||||
63 @unary_to_nary
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_wrapper.py in stack(arrays, axis)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py in stack(arrays, axis)
|
||||
86 # primitives defined in this file
|
||||
87
|
||||
---> 88 arrays = [array(arr) for arr in arrays]
|
||||
89 if not arrays:
|
||||
90 raise ValueError('need at least one array to stack')
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_wrapper.py in <listcomp>(.0)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_wrapper.py in <listcomp>(.0)
|
||||
86 # primitives defined in this file
|
||||
87
|
||||
---> 88 arrays = [array(arr) for arr in arrays]
|
||||
89 if not arrays:
|
||||
90 raise ValueError('need at least one array to stack')
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in vjp(g)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py in vjp(g)
|
||||
12 def vjp(g): return vspace(x).zeros()
|
||||
13 else:
|
||||
---> 14 def vjp(g): return backward_pass(g, end_node)
|
||||
15 return vjp, end_value
|
||||
16
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in backward_pass(g, end_node)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py in backward_pass(g, end_node)
|
||||
19 for node in toposort(end_node):
|
||||
20 outgrad = outgrads.pop(node)
|
||||
---> 21 ingrads = node.vjp(outgrad[0])
|
||||
22 for parent, ingrad in zip(node.parents, ingrads):
|
||||
23 outgrads[parent] = add_outgrads(outgrads.get(parent), ingrad)
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in <lambda>(g)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/core.py in <lambda>(g)
|
||||
65 "VJP of {} wrt argnum 0 not defined".format(fun.__name__))
|
||||
66 vjp = vjpfun(ans, *args, **kwargs)
|
||||
---> 67 return lambda g: (vjp(g),)
|
||||
68 elif L == 2:
|
||||
69 argnum_0, argnum_1 = argnums
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_vjps.py in <lambda>(g)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py in <lambda>(g)
|
||||
421 A_ndim = anp.ndim(A)
|
||||
422 B_meta = anp.metadata(B)
|
||||
--> 423 return lambda g: matmul_adjoint_1(A, g, A_ndim, B_meta)
|
||||
424
|
||||
425 defvjp(anp.matmul, matmul_vjp_0, matmul_vjp_1)
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_vjps.py in matmul_adjoint_1(A, G, A_ndim, B_meta)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/numpy/numpy_vjps.py in matmul_adjoint_1(A, G, A_ndim, B_meta)
|
||||
408 else: # We need to swap the last two axes of A
|
||||
409 A = anp.swapaxes(A, A_ndim - 2, A_ndim - 1)
|
||||
--> 410 result = anp.matmul(A, G)
|
||||
411 if B_is_vec:
|
||||
412 result = anp.squeeze(result, anp.ndim(G) - 1)
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/tracer.py in f_wrapped(*args, **kwargs)
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py in f_wrapped(*args, **kwargs)
|
||||
42 parents = tuple(box._node for _ , box in boxed_args)
|
||||
43 argnums = tuple(argnum for argnum, _ in boxed_args)
|
||||
44 ans = f_wrapped(*argvals, **kwargs)
|
||||
---> 45 node = node_constructor(ans, f_wrapped, argvals, kwargs, argnums, parents)
|
||||
---> 44 ans = f_wrapped(*argvals, **kwargs)
|
||||
45 node = node_constructor(ans, f_wrapped, argvals, kwargs, argnums, parents)
|
||||
46 return new_box(ans, trace, node)
|
||||
47 else:
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in __init__(self, value, fun, args, kwargs, parent_argnums, parents)
|
||||
34 raise NotImplementedError("VJP of {} wrt argnums {} not defined"
|
||||
35 .format(fun_name, parent_argnums))
|
||||
---> 36 self.vjp = vjpmaker(parent_argnums, value, args, kwargs)
|
||||
37
|
||||
38 def initialize_root(self):
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py in f_wrapped(*args, **kwargs)
|
||||
35 @wraps(f_raw)
|
||||
36 def f_wrapped(*args, **kwargs):
|
||||
---> 37 boxed_args, trace, node_constructor = find_top_boxed_args(args)
|
||||
38 if boxed_args:
|
||||
39 argvals = subvals(args, [(argnum, box._value) for argnum, box in boxed_args])
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/core.py in vjp_argnums(argnums, ans, args, kwargs)
|
||||
75 "VJP of {} wrt argnums 0, 1 not defined".format(fun.__name__))
|
||||
76 vjp_0 = vjp_0_fun(ans, *args, **kwargs)
|
||||
---> 77 vjp_1 = vjp_1_fun(ans, *args, **kwargs)
|
||||
78 return lambda g: (vjp_0(g), vjp_1(g))
|
||||
79 else:
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_vjps.py in matmul_vjp_1(ans, A, B)
|
||||
420 def matmul_vjp_1(ans, A, B):
|
||||
421 A_ndim = anp.ndim(A)
|
||||
--> 422 B_meta = anp.metadata(B)
|
||||
423 return lambda g: matmul_adjoint_1(A, g, A_ndim, B_meta)
|
||||
424
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/tracer.py in f_wrapped(*args, **kwargs)
|
||||
59 def f_wrapped(*args, **kwargs):
|
||||
60 argvals = map(getval, args)
|
||||
---> 61 return f_raw(*argvals, **kwargs)
|
||||
62 f_wrapped._is_primitive = True
|
||||
63 return f_wrapped
|
||||
|
||||
~/anaconda3/lib/python3.8/site-packages/autograd/numpy/numpy_wrapper.py in metadata(A)
|
||||
146 @notrace_primitive
|
||||
147 def metadata(A):
|
||||
--> 148 return _np.shape(A), _np.ndim(A), _np.result_type(A), _np.iscomplexobj(A)
|
||||
149
|
||||
150 @notrace_primitive
|
||||
~/miniforge3/envs/myenv/lib/python3.9/site-packages/autograd/tracer.py in find_top_boxed_args(args)
|
||||
68 top_node_type = None
|
||||
69 for argnum, arg in enumerate(args):
|
||||
---> 70 if isbox(arg):
|
||||
71 trace = arg._trace
|
||||
72 if trace > top_trace:
|
||||
|
||||
KeyboardInterrupt:
|
||||
</pre></div>
|
||||
@@ -2900,54 +2987,42 @@ g(x,t) = \sin(\pi x)\cos(\pi t) - \sin(\pi x)\sin(\pi t)
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class='prev-next-bottom'>
|
||||
|
||||
<div id="prev">
|
||||
<a class="left-prev" href="chapter10.html" title="previous page">
|
||||
<i class="prevnext-label fas fa-angle-left"></i>
|
||||
<div class="prevnext-info">
|
||||
<p class="prevnext-label">previous</p>
|
||||
<p class="prevnext-title"><span class="section-number">14. </span>Building a Feed Forward Neural Network</p>
|
||||
</div>
|
||||
</a>
|
||||
<!-- Previous / next buttons -->
|
||||
<div class='prev-next-area'>
|
||||
<a class='left-prev' id="prev-link" href="chapter10.html" title="previous page">
|
||||
<i class="fas fa-angle-left"></i>
|
||||
<div class="prev-next-info">
|
||||
<p class="prev-next-subtitle">previous</p>
|
||||
<p class="prev-next-title"><span class="section-number">14. </span>Building a Feed Forward Neural Network</p>
|
||||
</div>
|
||||
</a>
|
||||
<a class='right-next' id="next-link" href="chapter12.html" title="next page">
|
||||
<div class="prev-next-info">
|
||||
<p class="prev-next-subtitle">next</p>
|
||||
<p class="prev-next-title"><span class="section-number">16. </span>Convolutional Neural Networks</p>
|
||||
</div>
|
||||
<div id="next">
|
||||
<a class="right-next" href="chapter12.html" title="next page">
|
||||
<div class="prevnext-info">
|
||||
<p class="prevnext-label">next</p>
|
||||
<p class="prevnext-title"><span class="section-number">16. </span>Convolutional Neural Networks</p>
|
||||
</div>
|
||||
<i class="prevnext-label fas fa-angle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<i class="fas fa-angle-right"></i>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<footer class="footer">
|
||||
<div class="container">
|
||||
<p>
|
||||
|
||||
By Morten Hjorth-Jensen<br/>
|
||||
|
||||
© Copyright 2021.<br/>
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
<p>
|
||||
|
||||
By Morten Hjorth-Jensen<br/>
|
||||
|
||||
© Copyright 2021.<br/>
|
||||
</p>
|
||||
</footer>
|
||||
</main>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="_static/js/index.1c5a1a01449ed65a7b51.js"></script>
|
||||
<script src="_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user