692 lines
52 KiB
HTML
692 lines
52 KiB
HTML
<!--
|
||
Automatically generated HTML file from DocOnce source
|
||
(https://github.com/doconce/doconce/)
|
||
-->
|
||
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<meta name="generator" content="DocOnce: https://github.com/doconce/doconce/" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||
<meta name="description" content="Week 42 Solving differential equations and Convolutional (CNN)">
|
||
|
||
<title>Week 42 Solving differential equations and Convolutional (CNN)</title>
|
||
|
||
<!-- Bootstrap style: bootstrap -->
|
||
<link href="https://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
|
||
<!-- not necessary
|
||
<link href="https://netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet">
|
||
-->
|
||
|
||
<style type="text/css">
|
||
|
||
/* Add scrollbar to dropdown menus in bootstrap navigation bar */
|
||
.dropdown-menu {
|
||
height: auto;
|
||
max-height: 400px;
|
||
overflow-x: hidden;
|
||
}
|
||
|
||
/* Adds an invisible element before each target to offset for the navigation
|
||
bar */
|
||
.anchor::before {
|
||
content:"";
|
||
display:block;
|
||
height:50px; /* fixed header height for style bootstrap */
|
||
margin:-50px 0 0; /* negative fixed header height */
|
||
}
|
||
</style>
|
||
|
||
|
||
</head>
|
||
|
||
<!-- tocinfo
|
||
{'highest level': 2,
|
||
'sections': [('Plan for week 42', 2, None, 'plan-for-week-42'),
|
||
('Using Automatic differentiation',
|
||
2,
|
||
None,
|
||
'using-automatic-differentiation'),
|
||
('Solving ODEs with Deep Learning',
|
||
2,
|
||
None,
|
||
'solving-odes-with-deep-learning'),
|
||
('Ordinary Differential Equations',
|
||
2,
|
||
None,
|
||
'ordinary-differential-equations'),
|
||
('The trial solution', 2, None, 'the-trial-solution'),
|
||
('Minimization process', 2, None, 'minimization-process'),
|
||
('Minimizing the cost function using gradient descent and '
|
||
'automatic differentiation',
|
||
2,
|
||
None,
|
||
'minimizing-the-cost-function-using-gradient-descent-and-automatic-differentiation'),
|
||
('Example: Exponential decay',
|
||
2,
|
||
None,
|
||
'example-exponential-decay'),
|
||
('The function to solve for',
|
||
2,
|
||
None,
|
||
'the-function-to-solve-for'),
|
||
('The trial solution', 2, None, 'the-trial-solution'),
|
||
('Setup of Network', 2, None, 'setup-of-network'),
|
||
('Reformulating the problem',
|
||
2,
|
||
None,
|
||
'reformulating-the-problem'),
|
||
('More technicalities', 2, None, 'more-technicalities'),
|
||
('More details', 2, None, 'more-details'),
|
||
('A possible implementation of a neural network',
|
||
2,
|
||
None,
|
||
'a-possible-implementation-of-a-neural-network'),
|
||
('Technicalities', 2, None, 'technicalities'),
|
||
('Final technicalities I', 2, None, 'final-technicalities-i'),
|
||
('Final technicalities II', 2, None, 'final-technicalities-ii'),
|
||
('Final technicalities III', 2, None, 'final-technicalities-iii'),
|
||
('Final technicalities IV', 2, None, 'final-technicalities-iv'),
|
||
('Back propagation', 2, None, 'back-propagation'),
|
||
('Gradient descent', 2, None, 'gradient-descent'),
|
||
('The code for solving the ODE',
|
||
2,
|
||
None,
|
||
'the-code-for-solving-the-ode'),
|
||
('The network with one input layer, specified number of hidden '
|
||
'layers, and one output layer',
|
||
2,
|
||
None,
|
||
'the-network-with-one-input-layer-specified-number-of-hidden-layers-and-one-output-layer'),
|
||
('Example: Population growth',
|
||
2,
|
||
None,
|
||
'example-population-growth'),
|
||
('Setting up the problem', 2, None, 'setting-up-the-problem'),
|
||
('The trial solution', 2, None, 'the-trial-solution'),
|
||
('The program using Autograd',
|
||
2,
|
||
None,
|
||
'the-program-using-autograd'),
|
||
('Using forward Euler to solve the ODE',
|
||
2,
|
||
None,
|
||
'using-forward-euler-to-solve-the-ode'),
|
||
('Example: Solving the one dimensional Poisson equation',
|
||
2,
|
||
None,
|
||
'example-solving-the-one-dimensional-poisson-equation'),
|
||
('The specific equation to solve for',
|
||
2,
|
||
None,
|
||
'the-specific-equation-to-solve-for'),
|
||
('Solving the equation using Autograd',
|
||
2,
|
||
None,
|
||
'solving-the-equation-using-autograd'),
|
||
('Comparing with a numerical scheme',
|
||
2,
|
||
None,
|
||
'comparing-with-a-numerical-scheme'),
|
||
('Setting up the code', 2, None, 'setting-up-the-code'),
|
||
('Partial Differential Equations',
|
||
2,
|
||
None,
|
||
'partial-differential-equations'),
|
||
('Type of problem', 2, None, 'type-of-problem'),
|
||
('Network requirements', 2, None, 'network-requirements'),
|
||
('More details', 2, None, 'more-details'),
|
||
('Example: The diffusion equation',
|
||
2,
|
||
None,
|
||
'example-the-diffusion-equation'),
|
||
('Defining the problem', 2, None, 'defining-the-problem'),
|
||
('Setting up the network using Autograd',
|
||
2,
|
||
None,
|
||
'setting-up-the-network-using-autograd'),
|
||
('Setting up the network using Autograd; The trial solution',
|
||
2,
|
||
None,
|
||
'setting-up-the-network-using-autograd-the-trial-solution'),
|
||
('Why the jacobian?', 2, None, 'why-the-jacobian'),
|
||
('Setting up the network using Autograd; The full program',
|
||
2,
|
||
None,
|
||
'setting-up-the-network-using-autograd-the-full-program'),
|
||
('Example: Solving the wave equation with Neural Networks',
|
||
2,
|
||
None,
|
||
'example-solving-the-wave-equation-with-neural-networks'),
|
||
('The problem to solve for', 2, None, 'the-problem-to-solve-for'),
|
||
('The trial solution', 2, None, 'the-trial-solution'),
|
||
('The analytical solution', 2, None, 'the-analytical-solution'),
|
||
('Solving the wave equation - the full program using Autograd',
|
||
2,
|
||
None,
|
||
'solving-the-wave-equation-the-full-program-using-autograd'),
|
||
('Resources on differential equations and deep learning',
|
||
2,
|
||
None,
|
||
'resources-on-differential-equations-and-deep-learning'),
|
||
('Convolutional Neural Networks (recognizing images)',
|
||
2,
|
||
None,
|
||
'convolutional-neural-networks-recognizing-images'),
|
||
('What is the Difference', 2, None, 'what-is-the-difference'),
|
||
('Neural Networks vs CNNs', 2, None, 'neural-networks-vs-cnns'),
|
||
('Why CNNS for images, sound files, medical images from CT scans '
|
||
'etc?',
|
||
2,
|
||
None,
|
||
'why-cnns-for-images-sound-files-medical-images-from-ct-scans-etc'),
|
||
('Regular NNs don’t scale well to full images',
|
||
2,
|
||
None,
|
||
'regular-nns-don-t-scale-well-to-full-images'),
|
||
('3D volumes of neurons', 2, None, '3d-volumes-of-neurons'),
|
||
('Layers used to build CNNs',
|
||
2,
|
||
None,
|
||
'layers-used-to-build-cnns'),
|
||
('Transforming images', 2, None, 'transforming-images'),
|
||
('CNNs in brief', 2, None, 'cnns-in-brief'),
|
||
('Key Idea', 2, None, 'key-idea'),
|
||
('Mathematics of CNNs', 2, None, 'mathematics-of-cnns'),
|
||
('Convolution Examples: Polynomial multiplication',
|
||
2,
|
||
None,
|
||
'convolution-examples-polynomial-multiplication'),
|
||
('Efficient Polynomial Multiplication',
|
||
2,
|
||
None,
|
||
'efficient-polynomial-multiplication'),
|
||
('A more efficient way of coding the above Convolution',
|
||
2,
|
||
None,
|
||
'a-more-efficient-way-of-coding-the-above-convolution'),
|
||
('Convolution Examples: Principle of Superposition and Periodic '
|
||
'Forces (Fourier Transforms)',
|
||
2,
|
||
None,
|
||
'convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms'),
|
||
('Principle of Superposition',
|
||
2,
|
||
None,
|
||
'principle-of-superposition'),
|
||
('Simple Code Example', 2, None, 'simple-code-example'),
|
||
('Wrapping up Fourier transforms',
|
||
2,
|
||
None,
|
||
'wrapping-up-fourier-transforms'),
|
||
('Finding the Coefficients', 2, None, 'finding-the-coefficients'),
|
||
('Final words on Fourier Transforms',
|
||
2,
|
||
None,
|
||
'final-words-on-fourier-transforms'),
|
||
('Two-dimensional Objects', 2, None, 'two-dimensional-objects'),
|
||
('Cross-Correlation', 2, None, 'cross-correlation'),
|
||
('More on Dimensionalities', 2, None, 'more-on-dimensionalities'),
|
||
('Further Dimensionality Remarks',
|
||
2,
|
||
None,
|
||
'further-dimensionality-remarks'),
|
||
('CNNs in more detail, Lecture from IN5400',
|
||
2,
|
||
None,
|
||
'cnns-in-more-detail-lecture-from-in5400'),
|
||
('CNNs in more detail, building convolutional neural networks in '
|
||
'Tensorflow and Keras',
|
||
2,
|
||
None,
|
||
'cnns-in-more-detail-building-convolutional-neural-networks-in-tensorflow-and-keras'),
|
||
('Setting it up', 2, None, 'setting-it-up'),
|
||
('The MNIST dataset again', 2, None, 'the-mnist-dataset-again'),
|
||
('Strong correlations', 2, None, 'strong-correlations'),
|
||
('Layers of a CNN', 2, None, 'layers-of-a-cnn'),
|
||
('Systematic reduction', 2, None, 'systematic-reduction'),
|
||
('Prerequisites: Collect and pre-process data',
|
||
2,
|
||
None,
|
||
'prerequisites-collect-and-pre-process-data'),
|
||
('Importing Keras and Tensorflow',
|
||
2,
|
||
None,
|
||
'importing-keras-and-tensorflow'),
|
||
('Running with Keras', 2, None, 'running-with-keras'),
|
||
('Final part', 2, None, 'final-part'),
|
||
('Final visualization', 2, None, 'final-visualization'),
|
||
('The CIFAR01 data set', 2, None, 'the-cifar01-data-set'),
|
||
('Verifying the data set', 2, None, 'verifying-the-data-set'),
|
||
('Set up the model', 2, None, 'set-up-the-model'),
|
||
('Add Dense layers on top', 2, None, 'add-dense-layers-on-top'),
|
||
('Compile and train the model',
|
||
2,
|
||
None,
|
||
'compile-and-train-the-model'),
|
||
('Finally, evaluate the model',
|
||
2,
|
||
None,
|
||
'finally-evaluate-the-model')]}
|
||
end of tocinfo -->
|
||
|
||
<body>
|
||
|
||
|
||
|
||
<script type="text/x-mathjax-config">
|
||
MathJax.Hub.Config({
|
||
TeX: {
|
||
equationNumbers: { autoNumber: "none" },
|
||
extensions: ["AMSmath.js", "AMSsymbols.js", "autobold.js", "color.js"]
|
||
}
|
||
});
|
||
</script>
|
||
<script type="text/javascript" async
|
||
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
|
||
</script>
|
||
|
||
|
||
|
||
|
||
<!-- Bootstrap navigation bar -->
|
||
<div class="navbar navbar-default navbar-fixed-top">
|
||
<div class="navbar-header">
|
||
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-responsive-collapse">
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
<span class="icon-bar"></span>
|
||
</button>
|
||
<a class="navbar-brand" href="week42-bs.html">Week 42 Solving differential equations and Convolutional (CNN)</a>
|
||
</div>
|
||
|
||
<div class="navbar-collapse collapse navbar-responsive-collapse">
|
||
<ul class="nav navbar-nav navbar-right">
|
||
<li class="dropdown">
|
||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Contents <b class="caret"></b></a>
|
||
<ul class="dropdown-menu">
|
||
<!-- navigation toc: --> <li><a href="._week42-bs001.html#plan-for-week-42" style="font-size: 80%;">Plan for week 42</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs002.html#using-automatic-differentiation" style="font-size: 80%;">Using Automatic differentiation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs003.html#solving-odes-with-deep-learning" style="font-size: 80%;">Solving ODEs with Deep Learning</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs004.html#ordinary-differential-equations" style="font-size: 80%;">Ordinary Differential Equations</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs047.html#the-trial-solution" style="font-size: 80%;">The trial solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs006.html#minimization-process" style="font-size: 80%;">Minimization process</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs007.html#minimizing-the-cost-function-using-gradient-descent-and-automatic-differentiation" style="font-size: 80%;">Minimizing the cost function using gradient descent and automatic differentiation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs008.html#example-exponential-decay" style="font-size: 80%;">Example: Exponential decay</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs009.html#the-function-to-solve-for" style="font-size: 80%;">The function to solve for</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs047.html#the-trial-solution" style="font-size: 80%;">The trial solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs011.html#setup-of-network" style="font-size: 80%;">Setup of Network</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs012.html#reformulating-the-problem" style="font-size: 80%;">Reformulating the problem</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs013.html#more-technicalities" style="font-size: 80%;">More technicalities</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs038.html#more-details" style="font-size: 80%;">More details</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs015.html#a-possible-implementation-of-a-neural-network" style="font-size: 80%;">A possible implementation of a neural network</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs016.html#technicalities" style="font-size: 80%;">Technicalities</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs017.html#final-technicalities-i" style="font-size: 80%;">Final technicalities I</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs018.html#final-technicalities-ii" style="font-size: 80%;">Final technicalities II</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs019.html#final-technicalities-iii" style="font-size: 80%;">Final technicalities III</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs020.html#final-technicalities-iv" style="font-size: 80%;">Final technicalities IV</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs021.html#back-propagation" style="font-size: 80%;">Back propagation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs022.html#gradient-descent" style="font-size: 80%;">Gradient descent</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs023.html#the-code-for-solving-the-ode" style="font-size: 80%;">The code for solving the ODE</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs024.html#the-network-with-one-input-layer-specified-number-of-hidden-layers-and-one-output-layer" style="font-size: 80%;">The network with one input layer, specified number of hidden layers, and one output layer</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs025.html#example-population-growth" style="font-size: 80%;">Example: Population growth</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs026.html#setting-up-the-problem" style="font-size: 80%;">Setting up the problem</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs047.html#the-trial-solution" style="font-size: 80%;">The trial solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs028.html#the-program-using-autograd" style="font-size: 80%;">The program using Autograd</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs029.html#using-forward-euler-to-solve-the-ode" style="font-size: 80%;">Using forward Euler to solve the ODE</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs030.html#example-solving-the-one-dimensional-poisson-equation" style="font-size: 80%;">Example: Solving the one dimensional Poisson equation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs031.html#the-specific-equation-to-solve-for" style="font-size: 80%;">The specific equation to solve for</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs032.html#solving-the-equation-using-autograd" style="font-size: 80%;">Solving the equation using Autograd</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs033.html#comparing-with-a-numerical-scheme" style="font-size: 80%;">Comparing with a numerical scheme</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs034.html#setting-up-the-code" style="font-size: 80%;">Setting up the code</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs035.html#partial-differential-equations" style="font-size: 80%;">Partial Differential Equations</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs036.html#type-of-problem" style="font-size: 80%;">Type of problem</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs037.html#network-requirements" style="font-size: 80%;">Network requirements</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs038.html#more-details" style="font-size: 80%;">More details</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs039.html#example-the-diffusion-equation" style="font-size: 80%;">Example: The diffusion equation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs040.html#defining-the-problem" style="font-size: 80%;">Defining the problem</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs041.html#setting-up-the-network-using-autograd" style="font-size: 80%;">Setting up the network using Autograd</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs042.html#setting-up-the-network-using-autograd-the-trial-solution" style="font-size: 80%;">Setting up the network using Autograd; The trial solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs043.html#why-the-jacobian" style="font-size: 80%;">Why the jacobian?</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs044.html#setting-up-the-network-using-autograd-the-full-program" style="font-size: 80%;">Setting up the network using Autograd; The full program</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs045.html#example-solving-the-wave-equation-with-neural-networks" style="font-size: 80%;">Example: Solving the wave equation with Neural Networks</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs046.html#the-problem-to-solve-for" style="font-size: 80%;">The problem to solve for</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs047.html#the-trial-solution" style="font-size: 80%;">The trial solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs048.html#the-analytical-solution" style="font-size: 80%;">The analytical solution</a></li>
|
||
<!-- navigation toc: --> <li><a href="#solving-the-wave-equation-the-full-program-using-autograd" style="font-size: 80%;">Solving the wave equation - the full program using Autograd</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs050.html#resources-on-differential-equations-and-deep-learning" style="font-size: 80%;">Resources on differential equations and deep learning</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs051.html#convolutional-neural-networks-recognizing-images" style="font-size: 80%;">Convolutional Neural Networks (recognizing images)</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs052.html#what-is-the-difference" style="font-size: 80%;">What is the Difference</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs053.html#neural-networks-vs-cnns" style="font-size: 80%;">Neural Networks vs CNNs</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs054.html#why-cnns-for-images-sound-files-medical-images-from-ct-scans-etc" style="font-size: 80%;">Why CNNS for images, sound files, medical images from CT scans etc?</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs055.html#regular-nns-don-t-scale-well-to-full-images" style="font-size: 80%;">Regular NNs don’t scale well to full images</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs056.html#3d-volumes-of-neurons" style="font-size: 80%;">3D volumes of neurons</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs057.html#layers-used-to-build-cnns" style="font-size: 80%;">Layers used to build CNNs</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs058.html#transforming-images" style="font-size: 80%;">Transforming images</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs059.html#cnns-in-brief" style="font-size: 80%;">CNNs in brief</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs060.html#key-idea" style="font-size: 80%;">Key Idea</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs061.html#mathematics-of-cnns" style="font-size: 80%;">Mathematics of CNNs</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs062.html#convolution-examples-polynomial-multiplication" style="font-size: 80%;">Convolution Examples: Polynomial multiplication</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs063.html#efficient-polynomial-multiplication" style="font-size: 80%;">Efficient Polynomial Multiplication</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs064.html#a-more-efficient-way-of-coding-the-above-convolution" style="font-size: 80%;">A more efficient way of coding the above Convolution</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs065.html#convolution-examples-principle-of-superposition-and-periodic-forces-fourier-transforms" style="font-size: 80%;">Convolution Examples: Principle of Superposition and Periodic Forces (Fourier Transforms)</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs066.html#principle-of-superposition" style="font-size: 80%;">Principle of Superposition</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs067.html#simple-code-example" style="font-size: 80%;">Simple Code Example</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs068.html#wrapping-up-fourier-transforms" style="font-size: 80%;">Wrapping up Fourier transforms</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs069.html#finding-the-coefficients" style="font-size: 80%;">Finding the Coefficients</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs070.html#final-words-on-fourier-transforms" style="font-size: 80%;">Final words on Fourier Transforms</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs071.html#two-dimensional-objects" style="font-size: 80%;">Two-dimensional Objects</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs072.html#cross-correlation" style="font-size: 80%;">Cross-Correlation</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs073.html#more-on-dimensionalities" style="font-size: 80%;">More on Dimensionalities</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs074.html#further-dimensionality-remarks" style="font-size: 80%;">Further Dimensionality Remarks</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs075.html#cnns-in-more-detail-lecture-from-in5400" style="font-size: 80%;">CNNs in more detail, Lecture from IN5400</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs076.html#cnns-in-more-detail-building-convolutional-neural-networks-in-tensorflow-and-keras" style="font-size: 80%;">CNNs in more detail, building convolutional neural networks in Tensorflow and Keras</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs077.html#setting-it-up" style="font-size: 80%;">Setting it up</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs078.html#the-mnist-dataset-again" style="font-size: 80%;">The MNIST dataset again</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs079.html#strong-correlations" style="font-size: 80%;">Strong correlations</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs080.html#layers-of-a-cnn" style="font-size: 80%;">Layers of a CNN</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs081.html#systematic-reduction" style="font-size: 80%;">Systematic reduction</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs082.html#prerequisites-collect-and-pre-process-data" style="font-size: 80%;">Prerequisites: Collect and pre-process data</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs083.html#importing-keras-and-tensorflow" style="font-size: 80%;">Importing Keras and Tensorflow</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs084.html#running-with-keras" style="font-size: 80%;">Running with Keras</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs085.html#final-part" style="font-size: 80%;">Final part</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs086.html#final-visualization" style="font-size: 80%;">Final visualization</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs087.html#the-cifar01-data-set" style="font-size: 80%;">The CIFAR01 data set</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs088.html#verifying-the-data-set" style="font-size: 80%;">Verifying the data set</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs089.html#set-up-the-model" style="font-size: 80%;">Set up the model</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs090.html#add-dense-layers-on-top" style="font-size: 80%;">Add Dense layers on top</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs091.html#compile-and-train-the-model" style="font-size: 80%;">Compile and train the model</a></li>
|
||
<!-- navigation toc: --> <li><a href="._week42-bs092.html#finally-evaluate-the-model" style="font-size: 80%;">Finally, evaluate the model</a></li>
|
||
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</div>
|
||
</div>
|
||
</div> <!-- end of navigation bar -->
|
||
|
||
<div class="container">
|
||
|
||
<p> </p><p> </p><p> </p> <!-- add vertical space -->
|
||
|
||
<a name="part0049"></a>
|
||
<!-- !split -->
|
||
|
||
<h2 id="solving-the-wave-equation-the-full-program-using-autograd" class="anchor">Solving the wave equation - the full program using Autograd </h2>
|
||
|
||
<p>
|
||
|
||
<!-- code=python (!bc pycod) typeset with pygments style "default" -->
|
||
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">autograd.numpy</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">np</span>
|
||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">autograd</span> <span style="color: #008000; font-weight: bold">import</span> hessian,grad
|
||
<span style="color: #008000; font-weight: bold">import</span> <span style="color: #0000FF; font-weight: bold">autograd.numpy.random</span> <span style="color: #008000; font-weight: bold">as</span> <span style="color: #0000FF; font-weight: bold">npr</span>
|
||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> cm
|
||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">matplotlib</span> <span style="color: #008000; font-weight: bold">import</span> pyplot <span style="color: #008000; font-weight: bold">as</span> plt
|
||
<span style="color: #008000; font-weight: bold">from</span> <span style="color: #0000FF; font-weight: bold">mpl_toolkits.mplot3d</span> <span style="color: #008000; font-weight: bold">import</span> axes3d
|
||
|
||
<span style="color: #408080; font-style: italic">## Set up the trial function:</span>
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">u</span>(x):
|
||
<span style="color: #008000; font-weight: bold">return</span> np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>x)
|
||
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">v</span>(x):
|
||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">-</span>np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>x)
|
||
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">h1</span>(point):
|
||
x,t <span style="color: #666666">=</span> point
|
||
<span style="color: #008000; font-weight: bold">return</span> (<span style="color: #666666">1</span> <span style="color: #666666">-</span> t<span style="color: #666666">**2</span>)<span style="color: #666666">*</span>u(x) <span style="color: #666666">+</span> t<span style="color: #666666">*</span>v(x)
|
||
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">g_trial</span>(point,P):
|
||
x,t <span style="color: #666666">=</span> point
|
||
<span style="color: #008000; font-weight: bold">return</span> h1(point) <span style="color: #666666">+</span> x<span style="color: #666666">*</span>(<span style="color: #666666">1-</span>x)<span style="color: #666666">*</span>t<span style="color: #666666">**2*</span>deep_neural_network(P,point)
|
||
|
||
<span style="color: #408080; font-style: italic">## Define the cost function</span>
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">cost_function</span>(P, x, t):
|
||
cost_sum <span style="color: #666666">=</span> <span style="color: #666666">0</span>
|
||
|
||
g_t_hessian_func <span style="color: #666666">=</span> hessian(g_trial)
|
||
|
||
<span style="color: #008000; font-weight: bold">for</span> x_ <span style="color: #AA22FF; font-weight: bold">in</span> x:
|
||
<span style="color: #008000; font-weight: bold">for</span> t_ <span style="color: #AA22FF; font-weight: bold">in</span> t:
|
||
point <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([x_,t_])
|
||
|
||
g_t_hessian <span style="color: #666666">=</span> g_t_hessian_func(point,P)
|
||
|
||
g_t_d2x <span style="color: #666666">=</span> g_t_hessian[<span style="color: #666666">0</span>][<span style="color: #666666">0</span>]
|
||
g_t_d2t <span style="color: #666666">=</span> g_t_hessian[<span style="color: #666666">1</span>][<span style="color: #666666">1</span>]
|
||
|
||
err_sqr <span style="color: #666666">=</span> ( (g_t_d2t <span style="color: #666666">-</span> g_t_d2x) )<span style="color: #666666">**2</span>
|
||
cost_sum <span style="color: #666666">+=</span> err_sqr
|
||
|
||
<span style="color: #008000; font-weight: bold">return</span> cost_sum <span style="color: #666666">/</span> (np<span style="color: #666666">.</span>size(t) <span style="color: #666666">*</span> np<span style="color: #666666">.</span>size(x))
|
||
|
||
<span style="color: #408080; font-style: italic">## The neural network</span>
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">sigmoid</span>(z):
|
||
<span style="color: #008000; font-weight: bold">return</span> <span style="color: #666666">1/</span>(<span style="color: #666666">1</span> <span style="color: #666666">+</span> np<span style="color: #666666">.</span>exp(<span style="color: #666666">-</span>z))
|
||
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">deep_neural_network</span>(deep_params, x):
|
||
<span style="color: #408080; font-style: italic"># x is now a point and a 1D numpy array; make it a column vector</span>
|
||
num_coordinates <span style="color: #666666">=</span> np<span style="color: #666666">.</span>size(x,<span style="color: #666666">0</span>)
|
||
x <span style="color: #666666">=</span> x<span style="color: #666666">.</span>reshape(num_coordinates,<span style="color: #666666">-1</span>)
|
||
|
||
num_points <span style="color: #666666">=</span> np<span style="color: #666666">.</span>size(x,<span style="color: #666666">1</span>)
|
||
|
||
<span style="color: #408080; font-style: italic"># N_hidden is the number of hidden layers</span>
|
||
N_hidden <span style="color: #666666">=</span> np<span style="color: #666666">.</span>size(deep_params) <span style="color: #666666">-</span> <span style="color: #666666">1</span> <span style="color: #408080; font-style: italic"># -1 since params consist of parameters to all the hidden layers AND the output layer</span>
|
||
|
||
<span style="color: #408080; font-style: italic"># Assume that the input layer does nothing to the input x</span>
|
||
x_input <span style="color: #666666">=</span> x
|
||
x_prev <span style="color: #666666">=</span> x_input
|
||
|
||
<span style="color: #408080; font-style: italic">## Hidden layers:</span>
|
||
|
||
<span style="color: #008000; font-weight: bold">for</span> l <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(N_hidden):
|
||
<span style="color: #408080; font-style: italic"># From the list of parameters P; find the correct weigths and bias for this layer</span>
|
||
w_hidden <span style="color: #666666">=</span> deep_params[l]
|
||
|
||
<span style="color: #408080; font-style: italic"># Add a row of ones to include bias</span>
|
||
x_prev <span style="color: #666666">=</span> np<span style="color: #666666">.</span>concatenate((np<span style="color: #666666">.</span>ones((<span style="color: #666666">1</span>,num_points)), x_prev ), axis <span style="color: #666666">=</span> <span style="color: #666666">0</span>)
|
||
|
||
z_hidden <span style="color: #666666">=</span> np<span style="color: #666666">.</span>matmul(w_hidden, x_prev)
|
||
x_hidden <span style="color: #666666">=</span> sigmoid(z_hidden)
|
||
|
||
<span style="color: #408080; font-style: italic"># Update x_prev such that next layer can use the output from this layer</span>
|
||
x_prev <span style="color: #666666">=</span> x_hidden
|
||
|
||
<span style="color: #408080; font-style: italic">## Output layer:</span>
|
||
|
||
<span style="color: #408080; font-style: italic"># Get the weights and bias for this layer</span>
|
||
w_output <span style="color: #666666">=</span> deep_params[<span style="color: #666666">-1</span>]
|
||
|
||
<span style="color: #408080; font-style: italic"># Include bias:</span>
|
||
x_prev <span style="color: #666666">=</span> np<span style="color: #666666">.</span>concatenate((np<span style="color: #666666">.</span>ones((<span style="color: #666666">1</span>,num_points)), x_prev), axis <span style="color: #666666">=</span> <span style="color: #666666">0</span>)
|
||
|
||
z_output <span style="color: #666666">=</span> np<span style="color: #666666">.</span>matmul(w_output, x_prev)
|
||
x_output <span style="color: #666666">=</span> z_output
|
||
|
||
<span style="color: #008000; font-weight: bold">return</span> x_output[<span style="color: #666666">0</span>][<span style="color: #666666">0</span>]
|
||
|
||
<span style="color: #408080; font-style: italic">## The analytical solution</span>
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">g_analytic</span>(point):
|
||
x,t <span style="color: #666666">=</span> point
|
||
<span style="color: #008000; font-weight: bold">return</span> np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>x)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>cos(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>t) <span style="color: #666666">-</span> np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>x)<span style="color: #666666">*</span>np<span style="color: #666666">.</span>sin(np<span style="color: #666666">.</span>pi<span style="color: #666666">*</span>t)
|
||
|
||
<span style="color: #008000; font-weight: bold">def</span> <span style="color: #0000FF">solve_pde_deep_neural_network</span>(x,t, num_neurons, num_iter, lmb):
|
||
<span style="color: #408080; font-style: italic">## Set up initial weigths and biases</span>
|
||
N_hidden <span style="color: #666666">=</span> np<span style="color: #666666">.</span>size(num_neurons)
|
||
|
||
<span style="color: #408080; font-style: italic">## Set up initial weigths and biases</span>
|
||
|
||
<span style="color: #408080; font-style: italic"># Initialize the list of parameters:</span>
|
||
P <span style="color: #666666">=</span> [<span style="color: #008000; font-weight: bold">None</span>]<span style="color: #666666">*</span>(N_hidden <span style="color: #666666">+</span> <span style="color: #666666">1</span>) <span style="color: #408080; font-style: italic"># + 1 to include the output layer</span>
|
||
|
||
P[<span style="color: #666666">0</span>] <span style="color: #666666">=</span> npr<span style="color: #666666">.</span>randn(num_neurons[<span style="color: #666666">0</span>], <span style="color: #666666">2</span> <span style="color: #666666">+</span> <span style="color: #666666">1</span> ) <span style="color: #408080; font-style: italic"># 2 since we have two points, +1 to include bias</span>
|
||
<span style="color: #008000; font-weight: bold">for</span> l <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(<span style="color: #666666">1</span>,N_hidden):
|
||
P[l] <span style="color: #666666">=</span> npr<span style="color: #666666">.</span>randn(num_neurons[l], num_neurons[l<span style="color: #666666">-1</span>] <span style="color: #666666">+</span> <span style="color: #666666">1</span>) <span style="color: #408080; font-style: italic"># +1 to include bias</span>
|
||
|
||
<span style="color: #408080; font-style: italic"># For the output layer</span>
|
||
P[<span style="color: #666666">-1</span>] <span style="color: #666666">=</span> npr<span style="color: #666666">.</span>randn(<span style="color: #666666">1</span>, num_neurons[<span style="color: #666666">-1</span>] <span style="color: #666666">+</span> <span style="color: #666666">1</span> ) <span style="color: #408080; font-style: italic"># +1 since bias is included</span>
|
||
|
||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Initial cost: '</span>,cost_function(P, x, t))
|
||
|
||
cost_function_grad <span style="color: #666666">=</span> grad(cost_function,<span style="color: #666666">0</span>)
|
||
|
||
<span style="color: #408080; font-style: italic"># Let the update be done num_iter times</span>
|
||
<span style="color: #008000; font-weight: bold">for</span> i <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(num_iter):
|
||
cost_grad <span style="color: #666666">=</span> cost_function_grad(P, x , t)
|
||
|
||
<span style="color: #008000; font-weight: bold">for</span> l <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">range</span>(N_hidden<span style="color: #666666">+1</span>):
|
||
P[l] <span style="color: #666666">=</span> P[l] <span style="color: #666666">-</span> lmb <span style="color: #666666">*</span> cost_grad[l]
|
||
|
||
|
||
<span style="color: #008000">print</span>(<span style="color: #BA2121">'Final cost: '</span>,cost_function(P, x, t))
|
||
|
||
<span style="color: #008000; font-weight: bold">return</span> P
|
||
|
||
<span style="color: #008000; font-weight: bold">if</span> <span style="color: #19177C">__name__</span> <span style="color: #666666">==</span> <span style="color: #BA2121">'__main__'</span>:
|
||
<span style="color: #408080; font-style: italic">### Use the neural network:</span>
|
||
npr<span style="color: #666666">.</span>seed(<span style="color: #666666">15</span>)
|
||
|
||
<span style="color: #408080; font-style: italic">## Decide the vales of arguments to the function to solve</span>
|
||
Nx <span style="color: #666666">=</span> <span style="color: #666666">10</span>; Nt <span style="color: #666666">=</span> <span style="color: #666666">10</span>
|
||
x <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>, <span style="color: #666666">1</span>, Nx)
|
||
t <span style="color: #666666">=</span> np<span style="color: #666666">.</span>linspace(<span style="color: #666666">0</span>,<span style="color: #666666">1</span>,Nt)
|
||
|
||
<span style="color: #408080; font-style: italic">## Set up the parameters for the network</span>
|
||
num_hidden_neurons <span style="color: #666666">=</span> [<span style="color: #666666">50</span>,<span style="color: #666666">20</span>]
|
||
num_iter <span style="color: #666666">=</span> <span style="color: #666666">1000</span>
|
||
lmb <span style="color: #666666">=</span> <span style="color: #666666">0.01</span>
|
||
|
||
P <span style="color: #666666">=</span> solve_pde_deep_neural_network(x,t, num_hidden_neurons, num_iter, lmb)
|
||
|
||
<span style="color: #408080; font-style: italic">## Store the results</span>
|
||
res <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((Nx, Nt))
|
||
res_analytical <span style="color: #666666">=</span> np<span style="color: #666666">.</span>zeros((Nx, Nt))
|
||
<span style="color: #008000; font-weight: bold">for</span> i,x_ <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(x):
|
||
<span style="color: #008000; font-weight: bold">for</span> j, t_ <span style="color: #AA22FF; font-weight: bold">in</span> <span style="color: #008000">enumerate</span>(t):
|
||
point <span style="color: #666666">=</span> np<span style="color: #666666">.</span>array([x_, t_])
|
||
res[i,j] <span style="color: #666666">=</span> g_trial(point,P)
|
||
|
||
res_analytical[i,j] <span style="color: #666666">=</span> g_analytic(point)
|
||
|
||
diff <span style="color: #666666">=</span> np<span style="color: #666666">.</span>abs(res <span style="color: #666666">-</span> res_analytical)
|
||
<span style="color: #008000">print</span>(<span style="color: #BA2121">"Max difference between analytical and solution from nn: </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">"</span><span style="color: #666666">%</span>np<span style="color: #666666">.</span>max(diff))
|
||
|
||
<span style="color: #408080; font-style: italic">## Plot the solutions in two dimensions, that being in position and time</span>
|
||
|
||
T,X <span style="color: #666666">=</span> np<span style="color: #666666">.</span>meshgrid(t,x)
|
||
|
||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
ax <span style="color: #666666">=</span> fig<span style="color: #666666">.</span>gca(projection<span style="color: #666666">=</span><span style="color: #BA2121">'3d'</span>)
|
||
ax<span style="color: #666666">.</span>set_title(<span style="color: #BA2121">'Solution from the deep neural network w/ </span><span style="color: #BB6688; font-weight: bold">%d</span><span style="color: #BA2121"> layer'</span><span style="color: #666666">%</span><span style="color: #008000">len</span>(num_hidden_neurons))
|
||
s <span style="color: #666666">=</span> ax<span style="color: #666666">.</span>plot_surface(T,X,res,linewidth<span style="color: #666666">=0</span>,antialiased<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>,cmap<span style="color: #666666">=</span>cm<span style="color: #666666">.</span>viridis)
|
||
ax<span style="color: #666666">.</span>set_xlabel(<span style="color: #BA2121">'Time $t$'</span>)
|
||
ax<span style="color: #666666">.</span>set_ylabel(<span style="color: #BA2121">'Position $x$'</span>);
|
||
|
||
|
||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
ax <span style="color: #666666">=</span> fig<span style="color: #666666">.</span>gca(projection<span style="color: #666666">=</span><span style="color: #BA2121">'3d'</span>)
|
||
ax<span style="color: #666666">.</span>set_title(<span style="color: #BA2121">'Analytical solution'</span>)
|
||
s <span style="color: #666666">=</span> ax<span style="color: #666666">.</span>plot_surface(T,X,res_analytical,linewidth<span style="color: #666666">=0</span>,antialiased<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>,cmap<span style="color: #666666">=</span>cm<span style="color: #666666">.</span>viridis)
|
||
ax<span style="color: #666666">.</span>set_xlabel(<span style="color: #BA2121">'Time $t$'</span>)
|
||
ax<span style="color: #666666">.</span>set_ylabel(<span style="color: #BA2121">'Position $x$'</span>);
|
||
|
||
|
||
fig <span style="color: #666666">=</span> plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
ax <span style="color: #666666">=</span> fig<span style="color: #666666">.</span>gca(projection<span style="color: #666666">=</span><span style="color: #BA2121">'3d'</span>)
|
||
ax<span style="color: #666666">.</span>set_title(<span style="color: #BA2121">'Difference'</span>)
|
||
s <span style="color: #666666">=</span> ax<span style="color: #666666">.</span>plot_surface(T,X,diff,linewidth<span style="color: #666666">=0</span>,antialiased<span style="color: #666666">=</span><span style="color: #008000; font-weight: bold">False</span>,cmap<span style="color: #666666">=</span>cm<span style="color: #666666">.</span>viridis)
|
||
ax<span style="color: #666666">.</span>set_xlabel(<span style="color: #BA2121">'Time $t$'</span>)
|
||
ax<span style="color: #666666">.</span>set_ylabel(<span style="color: #BA2121">'Position $x$'</span>);
|
||
|
||
<span style="color: #408080; font-style: italic">## Take some slices of the 3D plots just to see the solutions at particular times</span>
|
||
indx1 <span style="color: #666666">=</span> <span style="color: #666666">0</span>
|
||
indx2 <span style="color: #666666">=</span> <span style="color: #008000">int</span>(Nt<span style="color: #666666">/2</span>)
|
||
indx3 <span style="color: #666666">=</span> Nt<span style="color: #666666">-1</span>
|
||
|
||
t1 <span style="color: #666666">=</span> t[indx1]
|
||
t2 <span style="color: #666666">=</span> t[indx2]
|
||
t3 <span style="color: #666666">=</span> t[indx3]
|
||
|
||
<span style="color: #408080; font-style: italic"># Slice the results from the DNN</span>
|
||
res1 <span style="color: #666666">=</span> res[:,indx1]
|
||
res2 <span style="color: #666666">=</span> res[:,indx2]
|
||
res3 <span style="color: #666666">=</span> res[:,indx3]
|
||
|
||
<span style="color: #408080; font-style: italic"># Slice the analytical results</span>
|
||
res_analytical1 <span style="color: #666666">=</span> res_analytical[:,indx1]
|
||
res_analytical2 <span style="color: #666666">=</span> res_analytical[:,indx2]
|
||
res_analytical3 <span style="color: #666666">=</span> res_analytical[:,indx3]
|
||
|
||
<span style="color: #408080; font-style: italic"># Plot the slices</span>
|
||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Computed solutions at time = </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">"</span><span style="color: #666666">%</span>t1)
|
||
plt<span style="color: #666666">.</span>plot(x, res1)
|
||
plt<span style="color: #666666">.</span>plot(x,res_analytical1)
|
||
plt<span style="color: #666666">.</span>legend([<span style="color: #BA2121">'dnn'</span>,<span style="color: #BA2121">'analytical'</span>])
|
||
|
||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Computed solutions at time = </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">"</span><span style="color: #666666">%</span>t2)
|
||
plt<span style="color: #666666">.</span>plot(x, res2)
|
||
plt<span style="color: #666666">.</span>plot(x,res_analytical2)
|
||
plt<span style="color: #666666">.</span>legend([<span style="color: #BA2121">'dnn'</span>,<span style="color: #BA2121">'analytical'</span>])
|
||
|
||
plt<span style="color: #666666">.</span>figure(figsize<span style="color: #666666">=</span>(<span style="color: #666666">10</span>,<span style="color: #666666">10</span>))
|
||
plt<span style="color: #666666">.</span>title(<span style="color: #BA2121">"Computed solutions at time = </span><span style="color: #BB6688; font-weight: bold">%g</span><span style="color: #BA2121">"</span><span style="color: #666666">%</span>t3)
|
||
plt<span style="color: #666666">.</span>plot(x, res3)
|
||
plt<span style="color: #666666">.</span>plot(x,res_analytical3)
|
||
plt<span style="color: #666666">.</span>legend([<span style="color: #BA2121">'dnn'</span>,<span style="color: #BA2121">'analytical'</span>])
|
||
|
||
plt<span style="color: #666666">.</span>show()
|
||
</pre></div>
|
||
<p>
|
||
<p>
|
||
<!-- navigation buttons at the bottom of the page -->
|
||
<ul class="pagination">
|
||
<li><a href="._week42-bs048.html">«</a></li>
|
||
<li><a href="._week42-bs000.html">1</a></li>
|
||
<li><a href="">...</a></li>
|
||
<li><a href="._week42-bs041.html">42</a></li>
|
||
<li><a href="._week42-bs042.html">43</a></li>
|
||
<li><a href="._week42-bs043.html">44</a></li>
|
||
<li><a href="._week42-bs044.html">45</a></li>
|
||
<li><a href="._week42-bs045.html">46</a></li>
|
||
<li><a href="._week42-bs046.html">47</a></li>
|
||
<li><a href="._week42-bs047.html">48</a></li>
|
||
<li><a href="._week42-bs048.html">49</a></li>
|
||
<li class="active"><a href="._week42-bs049.html">50</a></li>
|
||
<li><a href="._week42-bs050.html">51</a></li>
|
||
<li><a href="._week42-bs051.html">52</a></li>
|
||
<li><a href="._week42-bs052.html">53</a></li>
|
||
<li><a href="._week42-bs053.html">54</a></li>
|
||
<li><a href="._week42-bs054.html">55</a></li>
|
||
<li><a href="._week42-bs055.html">56</a></li>
|
||
<li><a href="._week42-bs056.html">57</a></li>
|
||
<li><a href="._week42-bs057.html">58</a></li>
|
||
<li><a href="._week42-bs058.html">59</a></li>
|
||
<li><a href="">...</a></li>
|
||
<li><a href="._week42-bs092.html">93</a></li>
|
||
<li><a href="._week42-bs050.html">»</a></li>
|
||
</ul>
|
||
<!-- ------------------- end of main content --------------- -->
|
||
|
||
</div> <!-- end container -->
|
||
<!-- include javascript, jQuery *first* -->
|
||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
|
||
<script src="https://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
|
||
|
||
<!-- Bootstrap footer
|
||
<footer>
|
||
<a href="https://..."><img width="250" align=right src="https://..."></a>
|
||
</footer>
|
||
-->
|
||
|
||
|
||
<center style="font-size:80%">
|
||
<!-- copyright only on the titlepage -->
|
||
</center>
|
||
|
||
|
||
</body>
|
||
</html>
|
||
|
||
|