From 9477d0ffd1233eb00438d224b717a637c8b3d148 Mon Sep 17 00:00:00 2001 From: mhjensen Date: Sun, 11 Oct 2020 22:51:38 +0200 Subject: [PATCH] added files --- doc/pub/week42/html/reveal.js/.gitignore | 8 + doc/pub/week42/html/reveal.js/.travis.yml | 5 + doc/pub/week42/html/reveal.js/CONTRIBUTING.md | 23 + doc/pub/week42/html/reveal.js/Gruntfile.js | 140 + doc/pub/week42/html/reveal.js/LICENSE | 19 + doc/pub/week42/html/reveal.js/README.md | 1052 ++++ doc/pub/week42/html/reveal.js/bower.json | 27 + .../html/reveal.js/css/images/cbc_footer.png | Bin 0 -> 10008 bytes .../html/reveal.js/css/images/cbc_symbol.png | Bin 0 -> 2946 bytes .../reveal.js/css/images/simula_footer.png | Bin 0 -> 2513 bytes .../html/reveal.js/css/images/simula_logo.png | Bin 0 -> 2138 bytes .../reveal.js/css/images/simula_symbol.png | Bin 0 -> 2138 bytes .../html/reveal.js/css/images/uio_footer.png | Bin 0 -> 18189 bytes .../html/reveal.js/css/images/uio_symbol.png | Bin 0 -> 11352 bytes .../week42/html/reveal.js/css/print/paper.css | 202 + .../week42/html/reveal.js/css/print/pdf.css | 157 + doc/pub/week42/html/reveal.js/css/reveal.css | 1886 +++++++ doc/pub/week42/html/reveal.js/css/reveal.scss | 1319 +++++ .../week42/html/reveal.js/css/theme/README.md | 23 + .../week42/html/reveal.js/css/theme/beige.css | 154 + .../html/reveal.js/css/theme/beigesmall.css | 155 + .../week42/html/reveal.js/css/theme/black.css | 273 + .../week42/html/reveal.js/css/theme/blood.css | 180 + .../week42/html/reveal.js/css/theme/cbc.css | 144 + .../html/reveal.js/css/theme/darkgray.css | 153 + .../html/reveal.js/css/theme/default.css | 153 + .../html/reveal.js/css/theme/league.css | 279 + .../week42/html/reveal.js/css/theme/moon.css | 153 + .../week42/html/reveal.js/css/theme/night.css | 141 + .../week42/html/reveal.js/css/theme/serif.css | 143 + .../html/reveal.js/css/theme/simple.css | 144 + .../html/reveal.js/css/theme/simula.css | 144 + .../week42/html/reveal.js/css/theme/sky.css | 150 + .../html/reveal.js/css/theme/solarized.css | 153 + .../reveal.js/css/theme/source/beige.scss | 50 + .../css/theme/source/beigesmall.scss | 51 + .../reveal.js/css/theme/source/black.scss | 49 + .../reveal.js/css/theme/source/blood.scss | 91 + .../html/reveal.js/css/theme/source/cbc.scss | 39 + .../reveal.js/css/theme/source/darkgray.scss | 42 + .../reveal.js/css/theme/source/default.scss | 42 + .../reveal.js/css/theme/source/league.scss | 34 + .../html/reveal.js/css/theme/source/moon.scss | 68 + .../reveal.js/css/theme/source/night.scss | 35 + .../reveal.js/css/theme/source/serif.scss | 35 + .../reveal.js/css/theme/source/simple.scss | 38 + .../reveal.js/css/theme/source/simula.scss | 39 + .../html/reveal.js/css/theme/source/sky.scss | 46 + .../reveal.js/css/theme/source/solarized.scss | 74 + .../reveal.js/css/theme/source/white.scss | 49 + .../reveal.js/css/theme/template/mixins.scss | 29 + .../css/theme/template/settings.scss | 34 + .../reveal.js/css/theme/template/theme.scss | 171 + .../week42/html/reveal.js/css/theme/white.css | 273 + doc/pub/week42/html/reveal.js/index.html | 411 ++ doc/pub/week42/html/reveal.js/js/reveal.js | 4508 +++++++++++++++++ .../week42/html/reveal.js/lib/css/zenburn.css | 117 + .../reveal.js/lib/font/league-gothic/LICENSE | 2 + .../lib/font/league-gothic/league-gothic.css | 10 + .../lib/font/league-gothic/league-gothic.eot | Bin 0 -> 25696 bytes .../lib/font/league-gothic/league-gothic.ttf | Bin 0 -> 64256 bytes .../lib/font/league-gothic/league-gothic.woff | Bin 0 -> 30764 bytes .../lib/font/source-sans-pro/LICENSE | 45 + .../source-sans-pro-italic.eot | Bin 0 -> 75720 bytes .../source-sans-pro-italic.ttf | Bin 0 -> 238084 bytes .../source-sans-pro-italic.woff | Bin 0 -> 98556 bytes .../source-sans-pro-regular.eot | Bin 0 -> 88070 bytes .../source-sans-pro-regular.ttf | Bin 0 -> 288008 bytes .../source-sans-pro-regular.woff | Bin 0 -> 114324 bytes .../source-sans-pro-semibold.eot | Bin 0 -> 89897 bytes .../source-sans-pro-semibold.ttf | Bin 0 -> 284640 bytes .../source-sans-pro-semibold.woff | Bin 0 -> 115648 bytes .../source-sans-pro-semibolditalic.eot | Bin 0 -> 75706 bytes .../source-sans-pro-semibolditalic.ttf | Bin 0 -> 240944 bytes .../source-sans-pro-semibolditalic.woff | Bin 0 -> 98816 bytes .../font/source-sans-pro/source-sans-pro.css | 39 + .../week42/html/reveal.js/lib/js/classList.js | 2 + .../week42/html/reveal.js/lib/js/head.min.js | 8 + .../week42/html/reveal.js/lib/js/html5shiv.js | 7 + doc/pub/week42/html/reveal.js/package.json | 45 + .../reveal.js/plugin/highlight/highlight.js | 30 + .../week42/html/reveal.js/plugin/leap/leap.js | 159 + .../reveal.js/plugin/markdown/example.html | 129 + .../html/reveal.js/plugin/markdown/example.md | 31 + .../reveal.js/plugin/markdown/markdown.js | 393 ++ .../html/reveal.js/plugin/markdown/marked.js | 6 + .../week42/html/reveal.js/plugin/math/math.js | 64 + .../html/reveal.js/plugin/multiplex/client.js | 13 + .../html/reveal.js/plugin/multiplex/index.js | 56 + .../html/reveal.js/plugin/multiplex/master.js | 51 + .../reveal.js/plugin/notes-server/client.js | 60 + .../reveal.js/plugin/notes-server/index.js | 66 + .../reveal.js/plugin/notes-server/notes.html | 396 ++ .../html/reveal.js/plugin/notes/notes.html | 406 ++ .../html/reveal.js/plugin/notes/notes.js | 122 + .../reveal.js/plugin/print-pdf/print-pdf.js | 48 + .../html/reveal.js/plugin/remotes/remotes.js | 39 + .../html/reveal.js/plugin/search/search.js | 196 + .../html/reveal.js/plugin/zoom-js/zoom.js | 278 + .../reveal.js/test/examples/assets/image1.png | Bin 0 -> 21991 bytes .../reveal.js/test/examples/assets/image2.png | Bin 0 -> 10237 bytes .../reveal.js/test/examples/barebones.html | 41 + .../test/examples/embedded-media.html | 49 + .../html/reveal.js/test/examples/math.html | 185 + .../test/examples/slide-backgrounds.html | 144 + .../test/examples/slide-transitions.html | 101 + .../html/reveal.js/test/qunit-1.12.0.css | 244 + .../html/reveal.js/test/qunit-1.12.0.js | 2212 ++++++++ .../test-markdown-element-attributes.html | 134 + .../test/test-markdown-element-attributes.js | 46 + .../test/test-markdown-slide-attributes.html | 128 + .../test/test-markdown-slide-attributes.js | 47 + .../html/reveal.js/test/test-markdown.html | 52 + .../html/reveal.js/test/test-markdown.js | 15 + .../week42/html/reveal.js/test/test-pdf.html | 83 + .../week42/html/reveal.js/test/test-pdf.js | 15 + doc/pub/week42/html/reveal.js/test/test.html | 85 + doc/pub/week42/html/reveal.js/test/test.js | 589 +++ doc/pub/week42/html/week42-bs.html | 232 + doc/pub/week42/html/week42-reveal.html | 880 ++++ doc/pub/week42/html/week42-solarized.html | 703 +++ doc/pub/week42/html/week42.html | 708 +++ 122 files changed, 23099 insertions(+) create mode 100644 doc/pub/week42/html/reveal.js/.gitignore create mode 100644 doc/pub/week42/html/reveal.js/.travis.yml create mode 100644 doc/pub/week42/html/reveal.js/CONTRIBUTING.md create mode 100644 doc/pub/week42/html/reveal.js/Gruntfile.js create mode 100644 doc/pub/week42/html/reveal.js/LICENSE create mode 100644 doc/pub/week42/html/reveal.js/README.md create mode 100644 doc/pub/week42/html/reveal.js/bower.json create mode 100644 doc/pub/week42/html/reveal.js/css/images/cbc_footer.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/cbc_symbol.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/simula_footer.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/simula_logo.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/simula_symbol.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/uio_footer.png create mode 100644 doc/pub/week42/html/reveal.js/css/images/uio_symbol.png create mode 100644 doc/pub/week42/html/reveal.js/css/print/paper.css create mode 100644 doc/pub/week42/html/reveal.js/css/print/pdf.css create mode 100644 doc/pub/week42/html/reveal.js/css/reveal.css create mode 100644 doc/pub/week42/html/reveal.js/css/reveal.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/README.md create mode 100644 doc/pub/week42/html/reveal.js/css/theme/beige.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/beigesmall.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/black.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/blood.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/cbc.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/darkgray.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/default.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/league.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/moon.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/night.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/serif.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/simple.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/simula.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/sky.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/solarized.css create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/beige.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/beigesmall.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/black.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/blood.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/cbc.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/darkgray.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/default.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/league.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/moon.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/night.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/serif.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/simple.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/simula.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/sky.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/solarized.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/source/white.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/template/mixins.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/template/settings.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/template/theme.scss create mode 100644 doc/pub/week42/html/reveal.js/css/theme/white.css create mode 100644 doc/pub/week42/html/reveal.js/index.html create mode 100644 doc/pub/week42/html/reveal.js/js/reveal.js create mode 100644 doc/pub/week42/html/reveal.js/lib/css/zenburn.css create mode 100644 doc/pub/week42/html/reveal.js/lib/font/league-gothic/LICENSE create mode 100644 doc/pub/week42/html/reveal.js/lib/font/league-gothic/league-gothic.css create mode 100644 doc/pub/week42/html/reveal.js/lib/font/league-gothic/league-gothic.eot create mode 100644 doc/pub/week42/html/reveal.js/lib/font/league-gothic/league-gothic.ttf create mode 100644 doc/pub/week42/html/reveal.js/lib/font/league-gothic/league-gothic.woff create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/LICENSE create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-italic.eot create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-italic.ttf create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-italic.woff create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-regular.eot create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-regular.ttf create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-regular.woff create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibold.eot create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibold.ttf create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibold.woff create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibolditalic.eot create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibolditalic.ttf create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro-semibolditalic.woff create mode 100644 doc/pub/week42/html/reveal.js/lib/font/source-sans-pro/source-sans-pro.css create mode 100644 doc/pub/week42/html/reveal.js/lib/js/classList.js create mode 100644 doc/pub/week42/html/reveal.js/lib/js/head.min.js create mode 100644 doc/pub/week42/html/reveal.js/lib/js/html5shiv.js create mode 100644 doc/pub/week42/html/reveal.js/package.json create mode 100644 doc/pub/week42/html/reveal.js/plugin/highlight/highlight.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/leap/leap.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/markdown/example.html create mode 100644 doc/pub/week42/html/reveal.js/plugin/markdown/example.md create mode 100644 doc/pub/week42/html/reveal.js/plugin/markdown/markdown.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/markdown/marked.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/math/math.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/multiplex/client.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/multiplex/index.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/multiplex/master.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/notes-server/client.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/notes-server/index.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/notes-server/notes.html create mode 100644 doc/pub/week42/html/reveal.js/plugin/notes/notes.html create mode 100644 doc/pub/week42/html/reveal.js/plugin/notes/notes.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/print-pdf/print-pdf.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/remotes/remotes.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/search/search.js create mode 100644 doc/pub/week42/html/reveal.js/plugin/zoom-js/zoom.js create mode 100644 doc/pub/week42/html/reveal.js/test/examples/assets/image1.png create mode 100644 doc/pub/week42/html/reveal.js/test/examples/assets/image2.png create mode 100644 doc/pub/week42/html/reveal.js/test/examples/barebones.html create mode 100644 doc/pub/week42/html/reveal.js/test/examples/embedded-media.html create mode 100644 doc/pub/week42/html/reveal.js/test/examples/math.html create mode 100644 doc/pub/week42/html/reveal.js/test/examples/slide-backgrounds.html create mode 100644 doc/pub/week42/html/reveal.js/test/examples/slide-transitions.html create mode 100644 doc/pub/week42/html/reveal.js/test/qunit-1.12.0.css create mode 100644 doc/pub/week42/html/reveal.js/test/qunit-1.12.0.js create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown-element-attributes.html create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown-element-attributes.js create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown-slide-attributes.html create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown-slide-attributes.js create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown.html create mode 100644 doc/pub/week42/html/reveal.js/test/test-markdown.js create mode 100644 doc/pub/week42/html/reveal.js/test/test-pdf.html create mode 100644 doc/pub/week42/html/reveal.js/test/test-pdf.js create mode 100644 doc/pub/week42/html/reveal.js/test/test.html create mode 100644 doc/pub/week42/html/reveal.js/test/test.js create mode 100644 doc/pub/week42/html/week42-bs.html create mode 100644 doc/pub/week42/html/week42-reveal.html create mode 100644 doc/pub/week42/html/week42-solarized.html create mode 100644 doc/pub/week42/html/week42.html diff --git a/doc/pub/week42/html/reveal.js/.gitignore b/doc/pub/week42/html/reveal.js/.gitignore new file mode 100644 index 000000000..a5df3133d --- /dev/null +++ b/doc/pub/week42/html/reveal.js/.gitignore @@ -0,0 +1,8 @@ +.DS_Store +.svn +log/*.log +tmp/** +node_modules/ +.sass-cache +css/reveal.min.css +js/reveal.min.js diff --git a/doc/pub/week42/html/reveal.js/.travis.yml b/doc/pub/week42/html/reveal.js/.travis.yml new file mode 100644 index 000000000..165d9ae9f --- /dev/null +++ b/doc/pub/week42/html/reveal.js/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - 0.10 +before_script: + - npm install -g grunt-cli \ No newline at end of file diff --git a/doc/pub/week42/html/reveal.js/CONTRIBUTING.md b/doc/pub/week42/html/reveal.js/CONTRIBUTING.md new file mode 100644 index 000000000..c2091e88f --- /dev/null +++ b/doc/pub/week42/html/reveal.js/CONTRIBUTING.md @@ -0,0 +1,23 @@ +## Contributing + +Please keep the [issue tracker](http://github.com/hakimel/reveal.js/issues) limited to **bug reports**, **feature requests** and **pull requests**. + + +### Personal Support +If you have personal support or setup questions the best place to ask those are [StackOverflow](http://stackoverflow.com/questions/tagged/reveal.js). + + +### Bug Reports +When reporting a bug make sure to include information about which browser and operating system you are on as well as the necessary steps to reproduce the issue. If possible please include a link to a sample presentation where the bug can be tested. + + +### Pull Requests +- Should follow the coding style of the file you work in, most importantly: + - Tabs to indent + - Single-quoted strings +- Should be made towards the **dev branch** +- Should be submitted from a feature/topic branch (not your master) + + +### Plugins +Please do not submit plugins as pull requests. They should be maintained in their own separate repository. More information here: https://github.com/hakimel/reveal.js/wiki/Plugin-Guidelines diff --git a/doc/pub/week42/html/reveal.js/Gruntfile.js b/doc/pub/week42/html/reveal.js/Gruntfile.js new file mode 100644 index 000000000..b257e8f32 --- /dev/null +++ b/doc/pub/week42/html/reveal.js/Gruntfile.js @@ -0,0 +1,140 @@ +/* global module:false */ +module.exports = function(grunt) { + var port = grunt.option('port') || 8000; + // Project configuration + grunt.initConfig({ + pkg: grunt.file.readJSON('package.json'), + meta: { + banner: + '/*!\n' + + ' * reveal.js <%= pkg.version %> (<%= grunt.template.today("yyyy-mm-dd, HH:MM") %>)\n' + + ' * http://lab.hakim.se/reveal-js\n' + + ' * MIT licensed\n' + + ' *\n' + + ' * Copyright (C) 2014 Hakim El Hattab, http://hakim.se\n' + + ' */' + }, + + qunit: { + files: [ 'test/*.html' ] + }, + + uglify: { + options: { + banner: '<%= meta.banner %>\n' + }, + build: { + src: 'js/reveal.js', + dest: 'js/reveal.min.js' + } + }, + + cssmin: { + compress: { + files: { + 'css/reveal.min.css': [ 'css/reveal.css' ] + } + } + }, + + sass: { + main: { + files: { + 'css/theme/darkgray.css': 'css/theme/source/darkgray.scss', + 'css/theme/beigesmall.css': 'css/theme/source/beigesmall.scss', + 'css/theme/cbc.css': 'css/theme/source/cbc.scss', + 'css/theme/default.css': 'css/theme/source/default.scss', + 'css/theme/beige.css': 'css/theme/source/beige.scss', + 'css/theme/night.css': 'css/theme/source/night.scss', + 'css/theme/serif.css': 'css/theme/source/serif.scss', + 'css/theme/simple.css': 'css/theme/source/simple.scss', + 'css/theme/sky.css': 'css/theme/source/sky.scss', + 'css/theme/moon.css': 'css/theme/source/moon.scss', + 'css/theme/solarized.css': 'css/theme/source/solarized.scss', + 'css/theme/blood.css': 'css/theme/source/blood.scss' + } + } + }, + + jshint: { + options: { + curly: false, + eqeqeq: true, + immed: true, + latedef: true, + newcap: true, + noarg: true, + sub: true, + undef: true, + eqnull: true, + browser: true, + expr: true, + globals: { + head: false, + module: false, + console: false, + unescape: false + } + }, + files: [ 'Gruntfile.js', 'js/reveal.js' ] + }, + + connect: { + server: { + options: { + port: port, + base: '.' + } + } + }, + + zip: { + 'reveal-js-presentation.zip': [ + 'index.html', + 'css/**', + 'js/**', + 'lib/**', + 'images/**', + 'plugin/**' + ] + }, + + watch: { + main: { + files: [ 'Gruntfile.js', 'js/reveal.js', 'css/reveal.css' ], + tasks: 'default' + }, + theme: { + files: [ 'css/theme/source/*.scss', 'css/theme/template/*.scss' ], + tasks: 'themes' + } + } + + }); + + // Dependencies + grunt.loadNpmTasks( 'grunt-contrib-qunit' ); + grunt.loadNpmTasks( 'grunt-contrib-jshint' ); + grunt.loadNpmTasks( 'grunt-contrib-cssmin' ); + grunt.loadNpmTasks( 'grunt-contrib-uglify' ); + grunt.loadNpmTasks( 'grunt-contrib-watch' ); + grunt.loadNpmTasks( 'grunt-contrib-sass' ); + grunt.loadNpmTasks( 'grunt-contrib-connect' ); + grunt.loadNpmTasks( 'grunt-zip' ); + + // Default task + grunt.registerTask( 'default', [ 'jshint', 'cssmin', 'uglify', 'qunit' ] ); + + // Theme task + grunt.registerTask( 'themes', [ 'sass' ] ); + + // Package presentation to archive + grunt.registerTask( 'package', [ 'default', 'zip' ] ); + + // Serve presentation locally + grunt.registerTask( 'serve', [ 'connect', 'watch' ] ); + + // Run tests + grunt.registerTask( 'test', [ 'jshint', 'qunit' ] ); + +}; diff --git a/doc/pub/week42/html/reveal.js/LICENSE b/doc/pub/week42/html/reveal.js/LICENSE new file mode 100644 index 000000000..09623076f --- /dev/null +++ b/doc/pub/week42/html/reveal.js/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2015 Hakim El Hattab, http://hakim.se + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/doc/pub/week42/html/reveal.js/README.md b/doc/pub/week42/html/reveal.js/README.md new file mode 100644 index 000000000..573b19597 --- /dev/null +++ b/doc/pub/week42/html/reveal.js/README.md @@ -0,0 +1,1052 @@ +# reveal.js [![Build Status](https://travis-ci.org/hakimel/reveal.js.svg?branch=master)](https://travis-ci.org/hakimel/reveal.js) + +A framework for easily creating beautiful presentations using HTML. [Check out the live demo](http://lab.hakim.se/reveal-js/). + +reveal.js comes with a broad range of features including [nested slides](https://github.com/hakimel/reveal.js#markup), [Markdown contents](https://github.com/hakimel/reveal.js#markdown), [PDF export](https://github.com/hakimel/reveal.js#pdf-export), [speaker notes](https://github.com/hakimel/reveal.js#speaker-notes) and a [JavaScript API](https://github.com/hakimel/reveal.js#api). It's best viewed in a modern browser but [fallbacks](https://github.com/hakimel/reveal.js/wiki/Browser-Support) are available to make sure your presentation can still be viewed elsewhere. + + +#### More reading: +- [Installation](#installation): Step-by-step instructions for getting reveal.js running on your computer. +- [Changelog](https://github.com/hakimel/reveal.js/releases): Up-to-date version history. +- [Examples](https://github.com/hakimel/reveal.js/wiki/Example-Presentations): Presentations created with reveal.js, add your own! +- [Browser Support](https://github.com/hakimel/reveal.js/wiki/Browser-Support): Explanation of browser support and fallbacks. +- [Plugins](https://github.com/hakimel/reveal.js/wiki/Plugins,-Tools-and-Hardware): A list of plugins that can be used to extend reveal.js. + +## Online Editor + +Presentations are written using HTML or Markdown but there's also an online editor for those of you who prefer a graphical interface. Give it a try at [http://slides.com](http://slides.com). + + +## Instructions + +### Markup + +Markup hierarchy needs to be ``
`` where the ``
`` represents one slide and can be repeated indefinitely. If you place multiple ``
``'s inside of another ``
`` they will be shown as vertical slides. The first of the vertical slides is the "root" of the others (at the top), and it will be included in the horizontal sequence. For example: + +```html +
+
+
Single Horizontal Slide
+
+
Vertical Slide 1
+
Vertical Slide 2
+
+
+
+``` + +### Markdown + +It's possible to write your slides using Markdown. To enable Markdown, add the ```data-markdown``` attribute to your ```
``` elements and wrap the contents in a ``` +
+``` + +#### External Markdown + +You can write your content as a separate file and have reveal.js load it at runtime. Note the separator arguments which determine how slides are delimited in the external file. The ```data-charset``` attribute is optional and specifies which charset to use when loading the external file. + +When used locally, this feature requires that reveal.js [runs from a local web server](#full-setup). + +```html +
+
+``` + +#### Element Attributes + +Special syntax (in html comment) is available for adding attributes to Markdown elements. This is useful for fragments, amongst other things. + +```html +
+ +
+``` + +#### Slide Attributes + +Special syntax (in html comment) is available for adding attributes to the slide `
` elements generated by your Markdown. + +```html +
+ +
+``` + + +### Configuration + +At the end of your page you need to initialize reveal by running the following code. Note that all config values are optional and will default as specified below. + +```javascript +Reveal.initialize({ + + // Display controls in the bottom right corner + controls: true, + + // Display a presentation progress bar + progress: true, + + // Display the page number of the current slide + slideNumber: false, + + // Push each slide change to the browser history + history: false, + + // Enable keyboard shortcuts for navigation + keyboard: true, + + // Enable the slide overview mode + overview: true, + + // Vertical centering of slides + center: true, + + // Enables touch navigation on devices with touch input + touch: true, + + // Loop the presentation + loop: false, + + // Change the presentation direction to be RTL + rtl: false, + + // Turns fragments on and off globally + fragments: true, + + // Flags if the presentation is running in an embedded mode, + // i.e. contained within a limited portion of the screen + embedded: false, + + // Flags if we should show a help overlay when the questionmark + // key is pressed + help: true, + + // Number of milliseconds between automatically proceeding to the + // next slide, disabled when set to 0, this value can be overwritten + // by using a data-autoslide attribute on your slides + autoSlide: 0, + + // Stop auto-sliding after user input + autoSlideStoppable: true, + + // Enable slide navigation via mouse wheel + mouseWheel: false, + + // Hides the address bar on mobile devices + hideAddressBar: true, + + // Opens links in an iframe preview overlay + previewLinks: false, + + // Transition style + transition: 'default', // none/fade/slide/convex/concave/zoom + + // Transition speed + transitionSpeed: 'default', // default/fast/slow + + // Transition style for full page slide backgrounds + backgroundTransition: 'default', // none/fade/slide/convex/concave/zoom + + // Number of slides away from the current that are visible + viewDistance: 3, + + // Parallax background image + parallaxBackgroundImage: '', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'" + + // Parallax background size + parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" + + // Amount to move parallax background (horizontal and vertical) on slide change + // Number, e.g. 100 + parallaxBackgroundHorizontal: '', + parallaxBackgroundVertical: '' + +}); +``` + + +The configuration can be updated after initialization using the ```configure``` method: + +```javascript +// Turn autoSlide off +Reveal.configure({ autoSlide: 0 }); + +// Start auto-sliding every 5s +Reveal.configure({ autoSlide: 5000 }); +``` + + +### Dependencies + +Reveal.js doesn't _rely_ on any third party scripts to work but a few optional libraries are included by default. These libraries are loaded as dependencies in the order they appear, for example: + +```javascript +Reveal.initialize({ + dependencies: [ + // Cross-browser shim that fully implements classList - https://github.com/eligrey/classList.js/ + { src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } }, + + // Interpret Markdown in
elements + { src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, + { src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }, + + // Syntax highlight for elements + { src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }, + + // Zoom in and out with Alt+click + { src: 'plugin/zoom-js/zoom.js', async: true }, + + // Speaker notes + { src: 'plugin/notes/notes.js', async: true }, + + // Remote control your reveal.js presentation using a touch device + { src: 'plugin/remotes/remotes.js', async: true }, + + // MathJax + { src: 'plugin/math/math.js', async: true } + ] +}); +``` + +You can add your own extensions using the same syntax. The following properties are available for each dependency object: +- **src**: Path to the script to load +- **async**: [optional] Flags if the script should load after reveal.js has started, defaults to false +- **callback**: [optional] Function to execute when the script has loaded +- **condition**: [optional] Function which must return true for the script to be loaded + + +### Ready Event + +A 'ready' event is fired when reveal.js has loaded all non-async dependencies and is ready to start navigating. To check if reveal.js is already 'ready' you can call `Reveal.isReady()`. + +```javascript +Reveal.addEventListener( 'ready', function( event ) { + // event.currentSlide, event.indexh, event.indexv +} ); +``` + + +### Presentation Size + +All presentations have a normal size, that is the resolution at which they are authored. The framework will automatically scale presentations uniformly based on this size to ensure that everything fits on any given display or viewport. + +See below for a list of configuration options related to sizing, including default values: + +```javascript +Reveal.initialize({ + + ... + + // The "normal" size of the presentation, aspect ratio will be preserved + // when the presentation is scaled to fit different resolutions. Can be + // specified using percentage units. + width: 960, + height: 700, + + // Factor of the display size that should remain empty around the content + margin: 0.1, + + // Bounds for smallest/largest possible scale to apply to content + minScale: 0.2, + maxScale: 1.5 + +}); +``` + + +### Auto-sliding + +Presentations can be configured to progress through slides automatically, without any user input. To enable this you will need to tell the framework how many milliseconds it should wait between slides: + +```javascript +// Slide every five seconds +Reveal.configure({ + autoSlide: 5000 +}); +``` +When this is turned on a control element will appear that enables users to pause and resume auto-sliding. Alternatively, sliding can be paused or resumed by pressing »a« on the keyboard. Sliding is paused automatically as soon as the user starts navigating. You can disable these controls by specifying ```autoSlideStoppable: false``` in your reveal.js config. + +You can also override the slide duration for individual slides and fragments by using the ```data-autoslide``` attribute: + +```html +
+

After 2 seconds the first fragment will be shown.

+

After 10 seconds the next fragment will be shown.

+

Now, the fragment is displayed for 2 seconds before the next slide is shown.

+
+``` + +Whenever the auto-slide mode is resumed or paused the ```autoslideresumed``` and ```autoslidepaused``` events are fired. + + +### Keyboard Bindings + +If you're unhappy with any of the default keyboard bindings you can override them using the ```keyboard``` config option: + +```javascript +Reveal.configure({ + keyboard: { + 13: 'next', // go to the next slide when the ENTER key is pressed + 27: function() {}, // do something custom when ESC is pressed + 32: null // don't do anything when SPACE is pressed (i.e. disable a reveal.js default binding) + } +}); +``` + +### Lazy Loading + +When working on presentation with a lot of media or iframe content it's important to load lazily. Lazy loading means that reveal.js will only load content for the few slides nearest to the current slide. The number of slides that are preloaded is determined by the `viewDistance` configuration option. + +To enable lazy loading all you need to do is change your "src" attributes to "data-src" as shown below. This is supported for image, video, audio and iframe elements. Lazy loaded iframes will also unload when the containing slide is no longer visible. + +```html +
+ + + +
+``` + + +### API + +The ``Reveal`` object exposes a JavaScript API for controlling navigation and reading state: + +```javascript +// Navigation +Reveal.slide( indexh, indexv, indexf ); +Reveal.left(); +Reveal.right(); +Reveal.up(); +Reveal.down(); +Reveal.prev(); +Reveal.next(); +Reveal.prevFragment(); +Reveal.nextFragment(); + +// Toggle presentation states, optionally pass true/false to force on/off +Reveal.toggleOverview(); +Reveal.togglePause(); +Reveal.toggleAutoSlide(); + +// Change a config value at runtime +Reveal.configure({ controls: true }); + +// Returns the present configuration options +Reveal.getConfig(); + +// Fetch the current scale of the presentation +Reveal.getScale(); + +// Retrieves the previous and current slide elements +Reveal.getPreviousSlide(); +Reveal.getCurrentSlide(); + +Reveal.getIndices(); // { h: 0, v: 0 } } +Reveal.getProgress(); // 0-1 +Reveal.getTotalSlides(); + +// State checks +Reveal.isFirstSlide(); +Reveal.isLastSlide(); +Reveal.isOverview(); +Reveal.isPaused(); +Reveal.isAutoSliding(); +``` + +### Slide Changed Event + +A 'slidechanged' event is fired each time the slide is changed (regardless of state). The event object holds the index values of the current slide as well as a reference to the previous and current slide HTML nodes. + +Some libraries, like MathJax (see [#226](https://github.com/hakimel/reveal.js/issues/226#issuecomment-10261609)), get confused by the transforms and display states of slides. Often times, this can be fixed by calling their update or render function from this callback. + +```javascript +Reveal.addEventListener( 'slidechanged', function( event ) { + // event.previousSlide, event.currentSlide, event.indexh, event.indexv +} ); +``` + +### Presentation State + +The presentation's current state can be fetched by using the `getState` method. A state object contains all of the information required to put the presentation back as it was when `getState` was first called. Sort of like a snapshot. It's a simple object that can easily be stringified and persisted or sent over the wire. + +```javascript +Reveal.slide( 1 ); +// we're on slide 1 + +var state = Reveal.getState(); + +Reveal.slide( 3 ); +// we're on slide 3 + +Reveal.setState( state ); +// we're back on slide 1 +``` + +### Slide States + +If you set ``data-state="somestate"`` on a slide ``
``, "somestate" will be applied as a class on the document element when that slide is opened. This allows you to apply broad style changes to the page based on the active slide. + +Furthermore you can also listen to these changes in state via JavaScript: + +```javascript +Reveal.addEventListener( 'somestate', function() { + // TODO: Sprinkle magic +}, false ); +``` + +### Slide Backgrounds + +Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a ```data-background``` attribute to your ```
``` elements. Four different types of backgrounds are supported: color, image, video and iframe. Below are a few examples. + +```html +
+

All CSS color formats are supported, like rgba() or hsl().

+
+
+

This slide will have a full-size background image.

+
+
+

This background image will be sized to 100px and repeated.

+
+
+

Video. Multiple sources can be defined using a comma separated list. Video will loop when the data-background-video-loop attribute is provided.

+
+
+

Embeds a web page as a background. Note that the page won't be interactive.

+
+``` + +Backgrounds transition using a fade animation by default. This can be changed to a linear sliding transition by passing ```backgroundTransition: 'slide'``` to the ```Reveal.initialize()``` call. Alternatively you can set ```data-background-transition``` on any section with a background to override that specific transition. + + +### Parallax Background + +If you want to use a parallax scrolling background, set the first two config properties below when initializing reveal.js (the other two are optional). + +```javascript +Reveal.initialize({ + + // Parallax background image + parallaxBackgroundImage: '', // e.g. "https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg" + + // Parallax background size + parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" - currently only pixels are supported (don't use % or auto) + + // Amount of pixels to move the parallax background per slide step, + // a value of 0 disables movement along the given axis + // These are optional, if they aren't specified they'll be calculated automatically + parallaxBackgroundHorizontal: 200, + parallaxBackgroundVertical: 50 + +}); +``` + +Make sure that the background size is much bigger than screen size to allow for some scrolling. [View example](http://lab.hakim.se/reveal-js/?parallaxBackgroundImage=https%3A%2F%2Fs3.amazonaws.com%2Fhakim-static%2Freveal-js%2Freveal-parallax-1.jpg¶llaxBackgroundSize=2100px%20900px). + + + +### Slide Transitions +The global presentation transition is set using the ```transition``` config value. You can override the global transition for a specific slide by using the ```data-transition``` attribute: + +```html +
+

This slide will override the presentation transition and zoom!

+
+ +
+

Choose from three transition speeds: default, fast or slow!

+
+``` + +You can also use different in and out transitions for the same slide: + +```html +
+ The train goes on … +
+
+ and on … +
+
+ and stops. +
+
+ (Passengers entering and leaving) +
+
+ And it starts again. +
+``` + + +Note that this does not work with the page and cube transitions. + + +### Internal links + +It's easy to link between slides. The first example below targets the index of another slide whereas the second targets a slide with an ID attribute (```
```): + +```html +Link +Link +``` + +You can also add relative navigation links, similar to the built in reveal.js controls, by appending one of the following classes on any element. Note that each element is automatically given an ```enabled``` class when it's a valid navigation route based on the current slide. + +```html + + + + + + +``` + + +### Fragments +Fragments are used to highlight individual elements on a slide. Every element with the class ```fragment``` will be stepped through before moving on to the next slide. Here's an example: http://lab.hakim.se/reveal-js/#/fragments + +The default fragment style is to start out invisible and fade in. This style can be changed by appending a different class to the fragment: + +```html +
+

grow

+

shrink

+

fade-out

+

visible only once

+

blue only once

+

highlight-red

+

highlight-green

+

highlight-blue

+
+``` + +Multiple fragments can be applied to the same element sequentially by wrapping it, this will fade in the text on the first step and fade it back out on the second. + +```html +
+ + I'll fade in, then out + +
+``` + +The display order of fragments can be controlled using the ```data-fragment-index``` attribute. + +```html +
+

Appears last

+

Appears first

+

Appears second

+
+``` + +### Fragment events + +When a slide fragment is either shown or hidden reveal.js will dispatch an event. + +Some libraries, like MathJax (see #505), get confused by the initially hidden fragment elements. Often times this can be fixed by calling their update or render function from this callback. + +```javascript +Reveal.addEventListener( 'fragmentshown', function( event ) { + // event.fragment = the fragment DOM element +} ); +Reveal.addEventListener( 'fragmenthidden', function( event ) { + // event.fragment = the fragment DOM element +} ); +``` + +### Code syntax highlighting + +By default, Reveal is configured with [highlight.js](http://softwaremaniacs.org/soft/highlight/en/) for code syntax highlighting. Below is an example with clojure code that will be syntax highlighted. When the `data-trim` attribute is present surrounding whitespace is automatically removed. + +```html +
+

+(def lazy-fib
+  (concat
+   [0 1]
+   ((fn rfib [a b]
+        (lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
+	
+
+``` + +### Slide number +If you would like to display the page number of the current slide you can do so using the ```slideNumber``` configuration value. + +```javascript +// Shows the slide number using default formatting +Reveal.configure({ slideNumber: true }); + +// Slide number formatting can be configured using these variables: +// h: current slide's horizontal index +// v: current slide's vertical index +// c: current slide index (flattened) +// t: total number of slides (flattened) +Reveal.configure({ slideNumber: 'c / t' }); + +``` + + +### Overview mode + +Press "Esc" or "o" keys to toggle the overview mode on and off. While you're in this mode, you can still navigate between slides, +as if you were at 1,000 feet above your presentation. The overview mode comes with a few API hooks: + +```javascript +Reveal.addEventListener( 'overviewshown', function( event ) { /* ... */ } ); +Reveal.addEventListener( 'overviewhidden', function( event ) { /* ... */ } ); + +// Toggle the overview mode programmatically +Reveal.toggleOverview(); +``` + +### Fullscreen mode +Just press »F« on your keyboard to show your presentation in fullscreen mode. Press the »ESC« key to exit fullscreen mode. + + +### Embedded media +Embedded HTML5 `
+ +
+ +

 

 

 

+ + + + + + +
+

Week 42 Convolutional and Recurrent Neural Networks and Autoencoders

+ +

+ + +

+Morten Hjorth-Jensen [1, 2] +
+ +

+ + +

[1] Department of Physics, University of Oslo
+
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
+
+

+

Oct 10, 2020

+
+

+ + +

Read »

+ + +
+ +

+ +

+ + +
+ + + + + + + +
+ © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license +
+ + + + + + diff --git a/doc/pub/week42/html/week42-reveal.html b/doc/pub/week42/html/week42-reveal.html new file mode 100644 index 000000000..d23d7a5d2 --- /dev/null +++ b/doc/pub/week42/html/week42-reveal.html @@ -0,0 +1,880 @@ + + + + + + + +Week 42 Convolutional and Recurrent Neural Networks and Autoencoders + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+ + + + + + + + + + + + + + +
+ + + + +

Week 42 Convolutional and Recurrent Neural Networks and Autoencoders

+ +

+ + +

+Morten Hjorth-Jensen [1, 2] +
+ +

 
+ + +

[1] Department of Physics, University of Oslo
+
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
+
+

 
+

Oct 10, 2020

+
+

+ +

+ © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license +
+
+ + +
+

Plan for week 42

+ +
    +

  • Thursday: Convolutional Neural Networks and examples
  • +

  • Friday: Recurrent Neural Networks and Autoencoders
  • +
+

+ +Reading suggestions for both days: Aurelien Geron's chapters 13 and 14. Autoencoders are discussed in chapter 15 of Geron's text. +

+ + +
+

Convolutional Neural Networks (recognizing images)

+ +

+Convolutional neural networks (CNNs) were developed during the last +decade of the previous century, with a focus on character recognition +tasks. Nowadays, CNNs are a central element in the spectacular success +of deep learning methods. The success in for example image +classifications have made them a central tool for most machine +learning practitioners. + +

+CNNs are very similar to ordinary Neural Networks. +They are made up of neurons that have learnable weights and +biases. Each neuron receives some inputs, performs a dot product and +optionally follows it with a non-linearity. The whole network still +expresses a single differentiable score function: from the raw image +pixels on one end to class scores at the other. And they still have a +loss function (for example Softmax) on the last (fully-connected) layer +and all the tips/tricks we developed for learning regular Neural +Networks still apply (back propagation, gradient descent etc etc). + +

+What is the difference? CNN architectures make the explicit assumption that +the inputs are images, which allows us to encode certain properties +into the architecture. These then make the forward function more +efficient to implement and vastly reduce the amount of parameters in +the network. + +

+Here we provide only a superficial overview, for the more interested, we recommend highly the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231. + +

+Another good read is the article here https://arxiv.org/pdf/1603.07285.pdf. +

+ + +
+

Regular NNs don’t scale well to full images

+ +

+As an example, consider +an image of size \( 32\times 32\times 3 \) (32 wide, 32 high, 3 color channels), so a +single fully-connected neuron in a first hidden layer of a regular +Neural Network would have \( 32\times 32\times 3 = 3072 \) weights. This amount still +seems manageable, but clearly this fully-connected structure does not +scale to larger images. For example, an image of more respectable +size, say \( 200\times 200\times 3 \), would lead to neurons that have +\( 200\times 200\times 3 = 120,000 \) weights. + +

+We could have +several such neurons, and the parameters would add up quickly! Clearly, +this full connectivity is wasteful and the huge number of parameters +would quickly lead to possible overfitting. + +

+

+
+

Figure 1: A regular 3-layer Neural Network.

+

+
+
+ + +
+

3D volumes of neurons

+ +

+Convolutional Neural Networks take advantage of the fact that the +input consists of images and they constrain the architecture in a more +sensible way. + +

+In particular, unlike a regular Neural Network, the +layers of a CNN have neurons arranged in 3 dimensions: width, +height, depth. (Note that the word depth here refers to the third +dimension of an activation volume, not to the depth of a full Neural +Network, which can refer to the total number of layers in a network.) + +

+To understand it better, the above example of an image +with an input volume of +activations has dimensions \( 32\times 32\times 3 \) (width, height, +depth respectively). + +

+The neurons in a layer will +only be connected to a small region of the layer before it, instead of +all of the neurons in a fully-connected manner. Moreover, the final +output layer could for this specific image have dimensions \( 1\times 1 \times 10 \), +because by the +end of the CNN architecture we will reduce the full image into a +single vector of class scores, arranged along the depth +dimension. + +

+

+
+

Figure 2: A CNN arranges its neurons in three dimensions (width, height, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D output volume of neuron activations. In this example, the red input layer holds the image, so its width and height would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels).

+

+
+
+ + +
+

Layers used to build CNNs

+ +

+A simple CNN is a sequence of layers, and every layer of a CNN +transforms one volume of activations to another through a +differentiable function. We use three main types of layers to build +CNN architectures: Convolutional Layer, Pooling Layer, and +Fully-Connected Layer (exactly as seen in regular Neural Networks). We +will stack these layers to form a full CNN architecture. + +

+A simple CNN for image classification could have the architecture: + +

    +

  • INPUT (\( 32\times 32 \times 3 \)) will hold the raw pixel values of the image, in this case an image of width 32, height 32, and with three color channels R,G,B.
  • +

  • CONV (convolutional )layer will compute the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and a small region they are connected to in the input volume. This may result in volume such as \( [32\times 32\times 12] \) if we decided to use 12 filters.
  • +

  • RELU layer will apply an elementwise activation function, such as the \( max(0,x) \) thresholding at zero. This leaves the size of the volume unchanged (\( [32\times 32\times 12] \)).
  • +

  • POOL (pooling) layer will perform a downsampling operation along the spatial dimensions (width, height), resulting in volume such as \( [16\times 16\times 12] \).
  • +

  • FC (i.e. fully-connected) layer will compute the class scores, resulting in volume of size \( [1\times 1\times 10] \), where each of the 10 numbers correspond to a class score, such as among the 10 categories of the MNIST images we considered above . As with ordinary Neural Networks and as the name implies, each neuron in this layer will be connected to all the numbers in the previous volume.
  • +
+
+ + +
+

Transforming images

+ +

+CNNs transform the original image layer by layer from the original +pixel values to the final class scores. + +

+Observe that some layers contain +parameters and other don’t. In particular, the CNN layers perform +transformations that are a function of not only the activations in the +input volume, but also of the parameters (the weights and biases of +the neurons). On the other hand, the RELU/POOL layers will implement a +fixed function. The parameters in the CONV/FC layers will be trained +with gradient descent so that the class scores that the CNN computes +are consistent with the labels in the training set for each image. +

+ + +
+

CNNs in brief

+ +

+In summary: + +

    +

  • A CNN architecture is in the simplest case a list of Layers that transform the image volume into an output volume (e.g. holding the class scores)
  • +

  • There are a few distinct types of Layers (e.g. CONV/FC/RELU/POOL are by far the most popular)
  • +

  • Each Layer accepts an input 3D volume and transforms it to an output 3D volume through a differentiable function
  • +

  • Each Layer may or may not have parameters (e.g. CONV/FC do, RELU/POOL don’t)
  • +

  • Each Layer may or may not have additional hyperparameters (e.g. CONV/FC/POOL do, RELU doesn’t)
  • +
+

+ +For more material on convolutional networks, we strongly recommend +the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231 which is taught at Stanford University (consistently ranked as one of the top computer science programs in the world). Michael Nielsen's book is a must read, in particular chapter 6 which deals with CNNs. +

+ + +
+

CNNs in more detail, building convolutional neural networks in Tensorflow and Keras

+ +

+As discussed above, CNNs are neural networks built from the assumption that the inputs +to the network are 2D images. This is important because the number of features or pixels in images +grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. + +

+As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks +are the convolutional and pooling layers stacked in pairs between the input and the hidden layer. +In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D +matrices, typically 1 for each color dimension (Red, Green, Blue). +

+ + +
+

Setting it up

+ +

+It means that to represent the entire +dataset of images, we require a 4D matrix or tensor. This tensor has the dimensions: + +

 
+$$ +(n_{inputs},\, n_{pixels, width},\, n_{pixels, height},\, depth) . +$$ +

 
+

+ + +
+

The MNIST dataset again

+ +

+The MNIST dataset consists of grayscale images with a pixel size of +\( 28\times 28 \), meaning we require \( 28 \times 28 = 724 \) weights to each +neuron in the first hidden layer. + +

+If we were to analyze images of size \( 128\times 128 \) we would require +\( 128 \times 128 = 16384 \) weights to each neuron. Even worse if we were +dealing with color images, as most images are, we have an image matrix +of size \( 128\times 128 \) for each color dimension (Red, Green, Blue), +meaning 3 times the number of weights \( = 49152 \) are required for every +single neuron in the first hidden layer. +

+ + +
+

Strong correlations

+ +

+Images typically have strong local correlations, meaning that a small +part of the image varies little from its neighboring regions. If for +example we have an image of a blue car, we can roughly assume that a +small blue part of the image is surrounded by other blue regions. + +

+Therefore, instead of connecting every single pixel to a neuron in the +first hidden layer, as we have previously done with deep neural +networks, we can instead connect each neuron to a small part of the +image (in all 3 RGB depth dimensions). The size of each small area is +fixed, and known as a receptive. +

+ + +
+

Layers of a CNN

+The layers of a convolutional neural network arrange neurons in 3D: width, height and depth. +The input image is typically a square matrix of depth 3. + +

+A convolution is performed on the image which outputs +a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as filters. + +

+Each filter slides along the input image, taking the dot product +between each small part of the image and the filter, in all depth +dimensions. This is then passed through a non-linear function, +typically the Rectified Linear (ReLu) function, which serves as the +activation of the neurons in the first convolutional layer. This is +further passed through a pooling layer, which reduces the size of the +convolutional layer, e.g. by taking the maximum or average across some +small regions, and this serves as input to the next convolutional +layer. +

+ + +
+

Systematic reduction

+ +

+By systematically reducing the size of the input volume, through +convolution and pooling, the network should create representations of +small parts of the input, and then from them assemble representations +of larger areas. The final pooling layer is flattened to serve as +input to a hidden layer, such that each neuron in the final pooling +layer is connected to every single neuron in the hidden layer. This +then serves as input to the output layer, e.g. a softmax output for +classification. +

+ + +
+

Prerequisites: Collect and pre-process data

+

+ + +

# import necessary packages
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn import datasets
+
+
+# ensure the same random numbers appear every time
+np.random.seed(0)
+
+# display images in notebook
+%matplotlib inline
+plt.rcParams['figure.figsize'] = (12,12)
+
+
+# download MNIST dataset
+digits = datasets.load_digits()
+
+# define inputs and labels
+inputs = digits.images
+labels = digits.target
+
+# RGB images have a depth of 3
+# our images are grayscale so they should have a depth of 1
+inputs = inputs[:,:,:,np.newaxis]
+
+print("inputs = (n_inputs, pixel_width, pixel_height, depth) = " + str(inputs.shape))
+print("labels = (n_inputs) = " + str(labels.shape))
+
+
+# choose some random images to display
+n_inputs = len(inputs)
+indices = np.arange(n_inputs)
+random_indices = np.random.choice(indices, size=5)
+
+for i, image in enumerate(digits.images[random_indices]):
+    plt.subplot(1, 5, i+1)
+    plt.axis('off')
+    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
+    plt.title("Label: %d" % digits.target[random_indices[i]])
+plt.show()
+
+
+ + +
+

Importing Keras and Tensorflow

+

+ + +

from tensorflow.keras import datasets, layers, models
+from tensorflow.keras.layers import Input
+from tensorflow.keras.models import Sequential      #This allows appending layers to existing models
+from tensorflow.keras.layers import Dense           #This allows defining the characteristics of a particular layer
+from tensorflow.keras import optimizers             #This allows using whichever optimiser we want (sgd,adam,RMSprop)
+from tensorflow.keras import regularizers           #This allows using whichever regularizer we want (l1,l2,l1_l2)
+from tensorflow.keras.utils import to_categorical   #This allows using categorical cross entropy as the cost function
+#from tensorflow.keras import Conv2D
+#from tensorflow.keras import MaxPooling2D
+#from tensorflow.keras import Flatten
+
+from sklearn.model_selection import train_test_split
+
+# representation of labels
+labels = to_categorical(labels)
+
+# split into train and test data
+# one-liner from scikit-learn library
+train_size = 0.8
+test_size = 1 - train_size
+X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
+                                                    test_size=test_size)
+
+
+ + +
+

Running with Keras

+ +

+ + +

def create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd):
+    model = Sequential()
+    model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',
+              activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.MaxPooling2D(pool_size=(2, 2)))
+    model.add(layers.Flatten())
+    model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))
+    
+    sgd = optimizers.SGD(lr=eta)
+    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
+    
+    return model
+
+epochs = 100
+batch_size = 100
+input_shape = X_train.shape[1:4]
+receptive_field = 3
+n_filters = 10
+n_neurons_connected = 50
+n_categories = 10
+
+eta_vals = np.logspace(-5, 1, 7)
+lmbd_vals = np.logspace(-5, 1, 7)
+
+
+ + +
+

Final part

+ +

+ + +

CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
+        
+for i, eta in enumerate(eta_vals):
+    for j, lmbd in enumerate(lmbd_vals):
+        CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd)
+        CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
+        scores = CNN.evaluate(X_test, Y_test)
+        
+        CNN_keras[i][j] = CNN
+        
+        print("Learning rate = ", eta)
+        print("Lambda = ", lmbd)
+        print("Test accuracy: %.3f" % scores[1])
+        print()
+
+
+ + +
+

Final visualization

+ +

+ + +

# visual representation of grid search
+# uses seaborn heatmap, could probably do this in matplotlib
+import seaborn as sns
+
+sns.set()
+
+train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+
+for i in range(len(eta_vals)):
+    for j in range(len(lmbd_vals)):
+        CNN = CNN_keras[i][j]
+
+        train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]
+        test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]
+
+        
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Training Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Test Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+
+ + +
+

Recurrent neural networks: Overarching view

+ +

+Till now our focus has been, including convolutional neural networks +as well, on feedforward neural networks. The output or the activations +flow only in one direction, from the input layer to the output layer. + +

+A recurrent neural network (RNN) looks very much like a feedforward +neural network, except that it also has connections pointing +backward. + +

+RNNs are used to analyze time series data such as stock prices, and +tell you when to buy or sell. In autonomous driving systems, they can +anticipate car trajectories and help avoid accidents. More generally, +they can work on sequences of arbitrary lengths, rather than on +fixed-sized inputs like all the nets we have discussed so far. For +example, they can take sentences, documents, or audio samples as +input, making them extremely useful for natural language processing +systems such as automatic translation and speech-to-text. +

+ + +
+

Set up of an RNN

+ +

+The figure here displays a simple example of an RNN, with inputs \( x_t \) +at a given time \( t \) and outputs \( y_t \). Introducing time as a variable +offers an intutitive way of understanding these networks. In addition +to the inputs \( x_t \), the layer at a time \( t \) receives also as input +the output from the previous layer \( t-1 \), that is \( y_{t1} \). + +

+This means also that we need to have weights that link both the inputs +\( x_t \) to the outputs \( y_t \) as well as weights that link the output +from the previous time \( y_{t-1} \) and \( y_t \). The figure here shows an +example of a simple RNN. +

+ + +
+

Solving differential equations and eigenvalue problems with RNNs

+ +

+In our discussions of ordinary differential equations and partial +differential equations using neural networks. Here we will discuss how +we can solve say ordinary differential equations and eigenvalue +problems using RNNs. Eigenvalue problems can be solved using RNNs by +rewriting such a problems as a non-linear differential equation. + +

+Instead of starting with a well-known ordinary differential equation, +we start directly with an eigenvaule problem. +

+ + +
+

Long-Short Time Memory

+ +

+Discussions about dynamic unrolling through time. discuss memory cells, input and output +

+ + +
+

Autoencoders: Overarching view

+ +

+Autoencoders are artificial neural networks capable of learning +efficient representations of the input data (these representations are called codings) without +any supervision (i.e., the training set is unlabeled). These codings +typically have a much lower dimensionality than the input data, making +autoencoders useful for dimensionality reduction. + +

+More importantly, autoencoders act as powerful feature detectors, and +they can be used for unsupervised pretraining of deep neural networks. + +

+Lastly, they are capable of randomly generating new data that looks +very similar to the training data; this is called a generative +model. For example, you could train an autoencoder on pictures of +faces, and it would then be able to generate new faces. Surprisingly, +autoencoders work by simply learning to copy their inputs to their +outputs. This may sound like a trivial task, but we will see that +constraining the network in various ways can make it rather +difficult. For example, you can limit the size of the internal +representation, or you can add noise to the inputs and train the +network to recover the original inputs. These constraints prevent the +autoencoder from trivially copying the inputs directly to the outputs, +which forces it to learn efficient ways of representing the data. In +short, the codings are byproducts of the autoencoder’s attempt to +learn the identity function under some constraints. +

+ + +
+

Simple examples of Autoencoders

+
+ + + +
+
+ + + + + + + + + + + + diff --git a/doc/pub/week42/html/week42-solarized.html b/doc/pub/week42/html/week42-solarized.html new file mode 100644 index 000000000..7ec9bdf0a --- /dev/null +++ b/doc/pub/week42/html/week42-solarized.html @@ -0,0 +1,703 @@ + + + + + + + + +Week 42 Convolutional and Recurrent Neural Networks and Autoencoders + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

Week 42 Convolutional and Recurrent Neural Networks and Autoencoders

+ +

+ + +

+Morten Hjorth-Jensen [1, 2] +
+ +

+ + +

[1] Department of Physics, University of Oslo
+
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
+
+

+

Oct 10, 2020

+
+

+









+ +

Plan for week 42

+ +
    +
  • Thursday: Convolutional Neural Networks and examples
  • +
  • Friday: Recurrent Neural Networks and Autoencoders
  • +
+ +Reading suggestions for both days: Aurelien Geron's chapters 13 and 14. Autoencoders are discussed in chapter 15 of Geron's text. + +

+









+ +

Convolutional Neural Networks (recognizing images)

+ +

+Convolutional neural networks (CNNs) were developed during the last +decade of the previous century, with a focus on character recognition +tasks. Nowadays, CNNs are a central element in the spectacular success +of deep learning methods. The success in for example image +classifications have made them a central tool for most machine +learning practitioners. + +

+CNNs are very similar to ordinary Neural Networks. +They are made up of neurons that have learnable weights and +biases. Each neuron receives some inputs, performs a dot product and +optionally follows it with a non-linearity. The whole network still +expresses a single differentiable score function: from the raw image +pixels on one end to class scores at the other. And they still have a +loss function (for example Softmax) on the last (fully-connected) layer +and all the tips/tricks we developed for learning regular Neural +Networks still apply (back propagation, gradient descent etc etc). + +

+What is the difference? CNN architectures make the explicit assumption that +the inputs are images, which allows us to encode certain properties +into the architecture. These then make the forward function more +efficient to implement and vastly reduce the amount of parameters in +the network. + +

+Here we provide only a superficial overview, for the more interested, we recommend highly the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231. + +

+Another good read is the article here https://arxiv.org/pdf/1603.07285.pdf. + +

+









+ +

Regular NNs don’t scale well to full images

+ +

+As an example, consider +an image of size \( 32\times 32\times 3 \) (32 wide, 32 high, 3 color channels), so a +single fully-connected neuron in a first hidden layer of a regular +Neural Network would have \( 32\times 32\times 3 = 3072 \) weights. This amount still +seems manageable, but clearly this fully-connected structure does not +scale to larger images. For example, an image of more respectable +size, say \( 200\times 200\times 3 \), would lead to neurons that have +\( 200\times 200\times 3 = 120,000 \) weights. + +

+We could have +several such neurons, and the parameters would add up quickly! Clearly, +this full connectivity is wasteful and the huge number of parameters +would quickly lead to possible overfitting. + +

+

+
+

Figure 1: A regular 3-layer Neural Network.

+

+
+ +

+









+ +

3D volumes of neurons

+ +

+Convolutional Neural Networks take advantage of the fact that the +input consists of images and they constrain the architecture in a more +sensible way. + +

+In particular, unlike a regular Neural Network, the +layers of a CNN have neurons arranged in 3 dimensions: width, +height, depth. (Note that the word depth here refers to the third +dimension of an activation volume, not to the depth of a full Neural +Network, which can refer to the total number of layers in a network.) + +

+To understand it better, the above example of an image +with an input volume of +activations has dimensions \( 32\times 32\times 3 \) (width, height, +depth respectively). + +

+The neurons in a layer will +only be connected to a small region of the layer before it, instead of +all of the neurons in a fully-connected manner. Moreover, the final +output layer could for this specific image have dimensions \( 1\times 1 \times 10 \), +because by the +end of the CNN architecture we will reduce the full image into a +single vector of class scores, arranged along the depth +dimension. + +

+

+
+

Figure 2: A CNN arranges its neurons in three dimensions (width, height, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D output volume of neuron activations. In this example, the red input layer holds the image, so its width and height would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels).

+

+
+ +

+ + +

Layers used to build CNNs

+ +

+A simple CNN is a sequence of layers, and every layer of a CNN +transforms one volume of activations to another through a +differentiable function. We use three main types of layers to build +CNN architectures: Convolutional Layer, Pooling Layer, and +Fully-Connected Layer (exactly as seen in regular Neural Networks). We +will stack these layers to form a full CNN architecture. + +

+A simple CNN for image classification could have the architecture: + +

    +
  • INPUT (\( 32\times 32 \times 3 \)) will hold the raw pixel values of the image, in this case an image of width 32, height 32, and with three color channels R,G,B.
  • +
  • CONV (convolutional )layer will compute the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and a small region they are connected to in the input volume. This may result in volume such as \( [32\times 32\times 12] \) if we decided to use 12 filters.
  • +
  • RELU layer will apply an elementwise activation function, such as the \( max(0,x) \) thresholding at zero. This leaves the size of the volume unchanged (\( [32\times 32\times 12] \)).
  • +
  • POOL (pooling) layer will perform a downsampling operation along the spatial dimensions (width, height), resulting in volume such as \( [16\times 16\times 12] \).
  • +
  • FC (i.e. fully-connected) layer will compute the class scores, resulting in volume of size \( [1\times 1\times 10] \), where each of the 10 numbers correspond to a class score, such as among the 10 categories of the MNIST images we considered above . As with ordinary Neural Networks and as the name implies, each neuron in this layer will be connected to all the numbers in the previous volume.
  • +
+ +









+ +

Transforming images

+ +

+CNNs transform the original image layer by layer from the original +pixel values to the final class scores. + +

+Observe that some layers contain +parameters and other don’t. In particular, the CNN layers perform +transformations that are a function of not only the activations in the +input volume, but also of the parameters (the weights and biases of +the neurons). On the other hand, the RELU/POOL layers will implement a +fixed function. The parameters in the CONV/FC layers will be trained +with gradient descent so that the class scores that the CNN computes +are consistent with the labels in the training set for each image. + +

+









+ +

CNNs in brief

+ +

+In summary: + +

    +
  • A CNN architecture is in the simplest case a list of Layers that transform the image volume into an output volume (e.g. holding the class scores)
  • +
  • There are a few distinct types of Layers (e.g. CONV/FC/RELU/POOL are by far the most popular)
  • +
  • Each Layer accepts an input 3D volume and transforms it to an output 3D volume through a differentiable function
  • +
  • Each Layer may or may not have parameters (e.g. CONV/FC do, RELU/POOL don’t)
  • +
  • Each Layer may or may not have additional hyperparameters (e.g. CONV/FC/POOL do, RELU doesn’t)
  • +
+ +For more material on convolutional networks, we strongly recommend +the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231 which is taught at Stanford University (consistently ranked as one of the top computer science programs in the world). Michael Nielsen's book is a must read, in particular chapter 6 which deals with CNNs. + +

+









+ +

CNNs in more detail, building convolutional neural networks in Tensorflow and Keras

+ +

+As discussed above, CNNs are neural networks built from the assumption that the inputs +to the network are 2D images. This is important because the number of features or pixels in images +grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. + +

+As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks +are the convolutional and pooling layers stacked in pairs between the input and the hidden layer. +In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D +matrices, typically 1 for each color dimension (Red, Green, Blue). + +

+









+ +

Setting it up

+ +

+It means that to represent the entire +dataset of images, we require a 4D matrix or tensor. This tensor has the dimensions: +$$ +(n_{inputs},\, n_{pixels, width},\, n_{pixels, height},\, depth) . +$$ + +

+









+ +

The MNIST dataset again

+ +

+The MNIST dataset consists of grayscale images with a pixel size of +\( 28\times 28 \), meaning we require \( 28 \times 28 = 724 \) weights to each +neuron in the first hidden layer. + +

+If we were to analyze images of size \( 128\times 128 \) we would require +\( 128 \times 128 = 16384 \) weights to each neuron. Even worse if we were +dealing with color images, as most images are, we have an image matrix +of size \( 128\times 128 \) for each color dimension (Red, Green, Blue), +meaning 3 times the number of weights \( = 49152 \) are required for every +single neuron in the first hidden layer. + +

+









+ +

Strong correlations

+ +

+Images typically have strong local correlations, meaning that a small +part of the image varies little from its neighboring regions. If for +example we have an image of a blue car, we can roughly assume that a +small blue part of the image is surrounded by other blue regions. + +

+Therefore, instead of connecting every single pixel to a neuron in the +first hidden layer, as we have previously done with deep neural +networks, we can instead connect each neuron to a small part of the +image (in all 3 RGB depth dimensions). The size of each small area is +fixed, and known as a receptive. + +

+ + +

Layers of a CNN

+The layers of a convolutional neural network arrange neurons in 3D: width, height and depth. +The input image is typically a square matrix of depth 3. + +

+A convolution is performed on the image which outputs +a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as filters. + +

+Each filter slides along the input image, taking the dot product +between each small part of the image and the filter, in all depth +dimensions. This is then passed through a non-linear function, +typically the Rectified Linear (ReLu) function, which serves as the +activation of the neurons in the first convolutional layer. This is +further passed through a pooling layer, which reduces the size of the +convolutional layer, e.g. by taking the maximum or average across some +small regions, and this serves as input to the next convolutional +layer. + +

+









+ +

Systematic reduction

+ +

+By systematically reducing the size of the input volume, through +convolution and pooling, the network should create representations of +small parts of the input, and then from them assemble representations +of larger areas. The final pooling layer is flattened to serve as +input to a hidden layer, such that each neuron in the final pooling +layer is connected to every single neuron in the hidden layer. This +then serves as input to the output layer, e.g. a softmax output for +classification. + +

+









+ +

Prerequisites: Collect and pre-process data

+

+ + +

# import necessary packages
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn import datasets
+
+
+# ensure the same random numbers appear every time
+np.random.seed(0)
+
+# display images in notebook
+%matplotlib inline
+plt.rcParams['figure.figsize'] = (12,12)
+
+
+# download MNIST dataset
+digits = datasets.load_digits()
+
+# define inputs and labels
+inputs = digits.images
+labels = digits.target
+
+# RGB images have a depth of 3
+# our images are grayscale so they should have a depth of 1
+inputs = inputs[:,:,:,np.newaxis]
+
+print("inputs = (n_inputs, pixel_width, pixel_height, depth) = " + str(inputs.shape))
+print("labels = (n_inputs) = " + str(labels.shape))
+
+
+# choose some random images to display
+n_inputs = len(inputs)
+indices = np.arange(n_inputs)
+random_indices = np.random.choice(indices, size=5)
+
+for i, image in enumerate(digits.images[random_indices]):
+    plt.subplot(1, 5, i+1)
+    plt.axis('off')
+    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
+    plt.title("Label: %d" % digits.target[random_indices[i]])
+plt.show()
+
+

+









+ +

Importing Keras and Tensorflow

+

+ + +

from tensorflow.keras import datasets, layers, models
+from tensorflow.keras.layers import Input
+from tensorflow.keras.models import Sequential      #This allows appending layers to existing models
+from tensorflow.keras.layers import Dense           #This allows defining the characteristics of a particular layer
+from tensorflow.keras import optimizers             #This allows using whichever optimiser we want (sgd,adam,RMSprop)
+from tensorflow.keras import regularizers           #This allows using whichever regularizer we want (l1,l2,l1_l2)
+from tensorflow.keras.utils import to_categorical   #This allows using categorical cross entropy as the cost function
+#from tensorflow.keras import Conv2D
+#from tensorflow.keras import MaxPooling2D
+#from tensorflow.keras import Flatten
+
+from sklearn.model_selection import train_test_split
+
+# representation of labels
+labels = to_categorical(labels)
+
+# split into train and test data
+# one-liner from scikit-learn library
+train_size = 0.8
+test_size = 1 - train_size
+X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
+                                                    test_size=test_size)
+
+

+ + +

Running with Keras

+ +

+ + +

def create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd):
+    model = Sequential()
+    model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',
+              activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.MaxPooling2D(pool_size=(2, 2)))
+    model.add(layers.Flatten())
+    model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))
+    
+    sgd = optimizers.SGD(lr=eta)
+    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
+    
+    return model
+
+epochs = 100
+batch_size = 100
+input_shape = X_train.shape[1:4]
+receptive_field = 3
+n_filters = 10
+n_neurons_connected = 50
+n_categories = 10
+
+eta_vals = np.logspace(-5, 1, 7)
+lmbd_vals = np.logspace(-5, 1, 7)
+
+

+









+ +

Final part

+ +

+ + +

CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
+        
+for i, eta in enumerate(eta_vals):
+    for j, lmbd in enumerate(lmbd_vals):
+        CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd)
+        CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
+        scores = CNN.evaluate(X_test, Y_test)
+        
+        CNN_keras[i][j] = CNN
+        
+        print("Learning rate = ", eta)
+        print("Lambda = ", lmbd)
+        print("Test accuracy: %.3f" % scores[1])
+        print()
+
+

+









+ +

Final visualization

+ +

+ + +

# visual representation of grid search
+# uses seaborn heatmap, could probably do this in matplotlib
+import seaborn as sns
+
+sns.set()
+
+train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+
+for i in range(len(eta_vals)):
+    for j in range(len(lmbd_vals)):
+        CNN = CNN_keras[i][j]
+
+        train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]
+        test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]
+
+        
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Training Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Test Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+

+









+ +

Recurrent neural networks: Overarching view

+ +

+Till now our focus has been, including convolutional neural networks +as well, on feedforward neural networks. The output or the activations +flow only in one direction, from the input layer to the output layer. + +

+A recurrent neural network (RNN) looks very much like a feedforward +neural network, except that it also has connections pointing +backward. + +

+RNNs are used to analyze time series data such as stock prices, and +tell you when to buy or sell. In autonomous driving systems, they can +anticipate car trajectories and help avoid accidents. More generally, +they can work on sequences of arbitrary lengths, rather than on +fixed-sized inputs like all the nets we have discussed so far. For +example, they can take sentences, documents, or audio samples as +input, making them extremely useful for natural language processing +systems such as automatic translation and speech-to-text. + +

+









+ +

Set up of an RNN

+ +

+The figure here displays a simple example of an RNN, with inputs \( x_t \) +at a given time \( t \) and outputs \( y_t \). Introducing time as a variable +offers an intutitive way of understanding these networks. In addition +to the inputs \( x_t \), the layer at a time \( t \) receives also as input +the output from the previous layer \( t-1 \), that is \( y_{t1} \). + +

+This means also that we need to have weights that link both the inputs +\( x_t \) to the outputs \( y_t \) as well as weights that link the output +from the previous time \( y_{t-1} \) and \( y_t \). The figure here shows an +example of a simple RNN. + +

+









+ +

Solving differential equations and eigenvalue problems with RNNs

+ +

+In our discussions of ordinary differential equations and partial +differential equations using neural networks. Here we will discuss how +we can solve say ordinary differential equations and eigenvalue +problems using RNNs. Eigenvalue problems can be solved using RNNs by +rewriting such a problems as a non-linear differential equation. + +

+Instead of starting with a well-known ordinary differential equation, +we start directly with an eigenvaule problem. + +

+









+ +

Long-Short Time Memory

+ +

+Discussions about dynamic unrolling through time. discuss memory cells, input and output + +

+









+ +

Autoencoders: Overarching view

+ +

+Autoencoders are artificial neural networks capable of learning +efficient representations of the input data (these representations are called codings) without +any supervision (i.e., the training set is unlabeled). These codings +typically have a much lower dimensionality than the input data, making +autoencoders useful for dimensionality reduction. + +

+More importantly, autoencoders act as powerful feature detectors, and +they can be used for unsupervised pretraining of deep neural networks. + +

+Lastly, they are capable of randomly generating new data that looks +very similar to the training data; this is called a generative +model. For example, you could train an autoencoder on pictures of +faces, and it would then be able to generate new faces. Surprisingly, +autoencoders work by simply learning to copy their inputs to their +outputs. This may sound like a trivial task, but we will see that +constraining the network in various ways can make it rather +difficult. For example, you can limit the size of the internal +representation, or you can add noise to the inputs and train the +network to recover the original inputs. These constraints prevent the +autoencoder from trivially copying the inputs directly to the outputs, +which forces it to learn efficient ways of representing the data. In +short, the codings are byproducts of the autoencoder’s attempt to +learn the identity function under some constraints. + +

+









+ +

Simple examples of Autoencoders

+ +

+ + + + +

+ © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license +
+ + + + + + diff --git a/doc/pub/week42/html/week42.html b/doc/pub/week42/html/week42.html new file mode 100644 index 000000000..f411c41f0 --- /dev/null +++ b/doc/pub/week42/html/week42.html @@ -0,0 +1,708 @@ + + + + + + + + +Week 42 Convolutional and Recurrent Neural Networks and Autoencoders + + + + + + + + + + + + + + + + + + + + + + + +

Week 42 Convolutional and Recurrent Neural Networks and Autoencoders

+ +

+ + +

+Morten Hjorth-Jensen [1, 2] +
+ +

+ + +

[1] Department of Physics, University of Oslo
+
[2] Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
+
+

+

Oct 10, 2020

+
+

+









+ +

Plan for week 42

+ +
    +
  • Thursday: Convolutional Neural Networks and examples
  • +
  • Friday: Recurrent Neural Networks and Autoencoders
  • +
+ +Reading suggestions for both days: Aurelien Geron's chapters 13 and 14. Autoencoders are discussed in chapter 15 of Geron's text. + +

+









+ +

Convolutional Neural Networks (recognizing images)

+ +

+Convolutional neural networks (CNNs) were developed during the last +decade of the previous century, with a focus on character recognition +tasks. Nowadays, CNNs are a central element in the spectacular success +of deep learning methods. The success in for example image +classifications have made them a central tool for most machine +learning practitioners. + +

+CNNs are very similar to ordinary Neural Networks. +They are made up of neurons that have learnable weights and +biases. Each neuron receives some inputs, performs a dot product and +optionally follows it with a non-linearity. The whole network still +expresses a single differentiable score function: from the raw image +pixels on one end to class scores at the other. And they still have a +loss function (for example Softmax) on the last (fully-connected) layer +and all the tips/tricks we developed for learning regular Neural +Networks still apply (back propagation, gradient descent etc etc). + +

+What is the difference? CNN architectures make the explicit assumption that +the inputs are images, which allows us to encode certain properties +into the architecture. These then make the forward function more +efficient to implement and vastly reduce the amount of parameters in +the network. + +

+Here we provide only a superficial overview, for the more interested, we recommend highly the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231. + +

+Another good read is the article here https://arxiv.org/pdf/1603.07285.pdf. + +

+









+ +

Regular NNs don’t scale well to full images

+ +

+As an example, consider +an image of size \( 32\times 32\times 3 \) (32 wide, 32 high, 3 color channels), so a +single fully-connected neuron in a first hidden layer of a regular +Neural Network would have \( 32\times 32\times 3 = 3072 \) weights. This amount still +seems manageable, but clearly this fully-connected structure does not +scale to larger images. For example, an image of more respectable +size, say \( 200\times 200\times 3 \), would lead to neurons that have +\( 200\times 200\times 3 = 120,000 \) weights. + +

+We could have +several such neurons, and the parameters would add up quickly! Clearly, +this full connectivity is wasteful and the huge number of parameters +would quickly lead to possible overfitting. + +

+

+
+

Figure 1: A regular 3-layer Neural Network.

+

+
+ +

+









+ +

3D volumes of neurons

+ +

+Convolutional Neural Networks take advantage of the fact that the +input consists of images and they constrain the architecture in a more +sensible way. + +

+In particular, unlike a regular Neural Network, the +layers of a CNN have neurons arranged in 3 dimensions: width, +height, depth. (Note that the word depth here refers to the third +dimension of an activation volume, not to the depth of a full Neural +Network, which can refer to the total number of layers in a network.) + +

+To understand it better, the above example of an image +with an input volume of +activations has dimensions \( 32\times 32\times 3 \) (width, height, +depth respectively). + +

+The neurons in a layer will +only be connected to a small region of the layer before it, instead of +all of the neurons in a fully-connected manner. Moreover, the final +output layer could for this specific image have dimensions \( 1\times 1 \times 10 \), +because by the +end of the CNN architecture we will reduce the full image into a +single vector of class scores, arranged along the depth +dimension. + +

+

+
+

Figure 2: A CNN arranges its neurons in three dimensions (width, height, depth), as visualized in one of the layers. Every layer of a CNN transforms the 3D input volume to a 3D output volume of neuron activations. In this example, the red input layer holds the image, so its width and height would be the dimensions of the image, and the depth would be 3 (Red, Green, Blue channels).

+

+
+ +

+ + +

Layers used to build CNNs

+ +

+A simple CNN is a sequence of layers, and every layer of a CNN +transforms one volume of activations to another through a +differentiable function. We use three main types of layers to build +CNN architectures: Convolutional Layer, Pooling Layer, and +Fully-Connected Layer (exactly as seen in regular Neural Networks). We +will stack these layers to form a full CNN architecture. + +

+A simple CNN for image classification could have the architecture: + +

    +
  • INPUT (\( 32\times 32 \times 3 \)) will hold the raw pixel values of the image, in this case an image of width 32, height 32, and with three color channels R,G,B.
  • +
  • CONV (convolutional )layer will compute the output of neurons that are connected to local regions in the input, each computing a dot product between their weights and a small region they are connected to in the input volume. This may result in volume such as \( [32\times 32\times 12] \) if we decided to use 12 filters.
  • +
  • RELU layer will apply an elementwise activation function, such as the \( max(0,x) \) thresholding at zero. This leaves the size of the volume unchanged (\( [32\times 32\times 12] \)).
  • +
  • POOL (pooling) layer will perform a downsampling operation along the spatial dimensions (width, height), resulting in volume such as \( [16\times 16\times 12] \).
  • +
  • FC (i.e. fully-connected) layer will compute the class scores, resulting in volume of size \( [1\times 1\times 10] \), where each of the 10 numbers correspond to a class score, such as among the 10 categories of the MNIST images we considered above . As with ordinary Neural Networks and as the name implies, each neuron in this layer will be connected to all the numbers in the previous volume.
  • +
+ +









+ +

Transforming images

+ +

+CNNs transform the original image layer by layer from the original +pixel values to the final class scores. + +

+Observe that some layers contain +parameters and other don’t. In particular, the CNN layers perform +transformations that are a function of not only the activations in the +input volume, but also of the parameters (the weights and biases of +the neurons). On the other hand, the RELU/POOL layers will implement a +fixed function. The parameters in the CONV/FC layers will be trained +with gradient descent so that the class scores that the CNN computes +are consistent with the labels in the training set for each image. + +

+









+ +

CNNs in brief

+ +

+In summary: + +

    +
  • A CNN architecture is in the simplest case a list of Layers that transform the image volume into an output volume (e.g. holding the class scores)
  • +
  • There are a few distinct types of Layers (e.g. CONV/FC/RELU/POOL are by far the most popular)
  • +
  • Each Layer accepts an input 3D volume and transforms it to an output 3D volume through a differentiable function
  • +
  • Each Layer may or may not have parameters (e.g. CONV/FC do, RELU/POOL don’t)
  • +
  • Each Layer may or may not have additional hyperparameters (e.g. CONV/FC/POOL do, RELU doesn’t)
  • +
+ +For more material on convolutional networks, we strongly recommend +the course +IN5400 – Machine Learning for Image Analysis +and the slides of CS231 which is taught at Stanford University (consistently ranked as one of the top computer science programs in the world). Michael Nielsen's book is a must read, in particular chapter 6 which deals with CNNs. + +

+









+ +

CNNs in more detail, building convolutional neural networks in Tensorflow and Keras

+ +

+As discussed above, CNNs are neural networks built from the assumption that the inputs +to the network are 2D images. This is important because the number of features or pixels in images +grows very fast with the image size, and an enormous number of weights and biases are needed in order to build an accurate network. + +

+As before, we still have our input, a hidden layer and an output. What's novel about convolutional networks +are the convolutional and pooling layers stacked in pairs between the input and the hidden layer. +In addition, the data is no longer represented as a 2D feature matrix, instead each input is a number of 2D +matrices, typically 1 for each color dimension (Red, Green, Blue). + +

+









+ +

Setting it up

+ +

+It means that to represent the entire +dataset of images, we require a 4D matrix or tensor. This tensor has the dimensions: +$$ +(n_{inputs},\, n_{pixels, width},\, n_{pixels, height},\, depth) . +$$ + +

+









+ +

The MNIST dataset again

+ +

+The MNIST dataset consists of grayscale images with a pixel size of +\( 28\times 28 \), meaning we require \( 28 \times 28 = 724 \) weights to each +neuron in the first hidden layer. + +

+If we were to analyze images of size \( 128\times 128 \) we would require +\( 128 \times 128 = 16384 \) weights to each neuron. Even worse if we were +dealing with color images, as most images are, we have an image matrix +of size \( 128\times 128 \) for each color dimension (Red, Green, Blue), +meaning 3 times the number of weights \( = 49152 \) are required for every +single neuron in the first hidden layer. + +

+









+ +

Strong correlations

+ +

+Images typically have strong local correlations, meaning that a small +part of the image varies little from its neighboring regions. If for +example we have an image of a blue car, we can roughly assume that a +small blue part of the image is surrounded by other blue regions. + +

+Therefore, instead of connecting every single pixel to a neuron in the +first hidden layer, as we have previously done with deep neural +networks, we can instead connect each neuron to a small part of the +image (in all 3 RGB depth dimensions). The size of each small area is +fixed, and known as a receptive. + +

+ + +

Layers of a CNN

+The layers of a convolutional neural network arrange neurons in 3D: width, height and depth. +The input image is typically a square matrix of depth 3. + +

+A convolution is performed on the image which outputs +a 3D volume of neurons. The weights to the input are arranged in a number of 2D matrices, known as filters. + +

+Each filter slides along the input image, taking the dot product +between each small part of the image and the filter, in all depth +dimensions. This is then passed through a non-linear function, +typically the Rectified Linear (ReLu) function, which serves as the +activation of the neurons in the first convolutional layer. This is +further passed through a pooling layer, which reduces the size of the +convolutional layer, e.g. by taking the maximum or average across some +small regions, and this serves as input to the next convolutional +layer. + +

+









+ +

Systematic reduction

+ +

+By systematically reducing the size of the input volume, through +convolution and pooling, the network should create representations of +small parts of the input, and then from them assemble representations +of larger areas. The final pooling layer is flattened to serve as +input to a hidden layer, such that each neuron in the final pooling +layer is connected to every single neuron in the hidden layer. This +then serves as input to the output layer, e.g. a softmax output for +classification. + +

+









+ +

Prerequisites: Collect and pre-process data

+

+ + +

# import necessary packages
+import numpy as np
+import matplotlib.pyplot as plt
+from sklearn import datasets
+
+
+# ensure the same random numbers appear every time
+np.random.seed(0)
+
+# display images in notebook
+%matplotlib inline
+plt.rcParams['figure.figsize'] = (12,12)
+
+
+# download MNIST dataset
+digits = datasets.load_digits()
+
+# define inputs and labels
+inputs = digits.images
+labels = digits.target
+
+# RGB images have a depth of 3
+# our images are grayscale so they should have a depth of 1
+inputs = inputs[:,:,:,np.newaxis]
+
+print("inputs = (n_inputs, pixel_width, pixel_height, depth) = " + str(inputs.shape))
+print("labels = (n_inputs) = " + str(labels.shape))
+
+
+# choose some random images to display
+n_inputs = len(inputs)
+indices = np.arange(n_inputs)
+random_indices = np.random.choice(indices, size=5)
+
+for i, image in enumerate(digits.images[random_indices]):
+    plt.subplot(1, 5, i+1)
+    plt.axis('off')
+    plt.imshow(image, cmap=plt.cm.gray_r, interpolation='nearest')
+    plt.title("Label: %d" % digits.target[random_indices[i]])
+plt.show()
+
+

+









+ +

Importing Keras and Tensorflow

+

+ + +

from tensorflow.keras import datasets, layers, models
+from tensorflow.keras.layers import Input
+from tensorflow.keras.models import Sequential      #This allows appending layers to existing models
+from tensorflow.keras.layers import Dense           #This allows defining the characteristics of a particular layer
+from tensorflow.keras import optimizers             #This allows using whichever optimiser we want (sgd,adam,RMSprop)
+from tensorflow.keras import regularizers           #This allows using whichever regularizer we want (l1,l2,l1_l2)
+from tensorflow.keras.utils import to_categorical   #This allows using categorical cross entropy as the cost function
+#from tensorflow.keras import Conv2D
+#from tensorflow.keras import MaxPooling2D
+#from tensorflow.keras import Flatten
+
+from sklearn.model_selection import train_test_split
+
+# representation of labels
+labels = to_categorical(labels)
+
+# split into train and test data
+# one-liner from scikit-learn library
+train_size = 0.8
+test_size = 1 - train_size
+X_train, X_test, Y_train, Y_test = train_test_split(inputs, labels, train_size=train_size,
+                                                    test_size=test_size)
+
+

+ + +

Running with Keras

+ +

+ + +

def create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd):
+    model = Sequential()
+    model.add(layers.Conv2D(n_filters, (receptive_field, receptive_field), input_shape=input_shape, padding='same',
+              activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.MaxPooling2D(pool_size=(2, 2)))
+    model.add(layers.Flatten())
+    model.add(layers.Dense(n_neurons_connected, activation='relu', kernel_regularizer=regularizers.l2(lmbd)))
+    model.add(layers.Dense(n_categories, activation='softmax', kernel_regularizer=regularizers.l2(lmbd)))
+    
+    sgd = optimizers.SGD(lr=eta)
+    model.compile(loss='categorical_crossentropy', optimizer=sgd, metrics=['accuracy'])
+    
+    return model
+
+epochs = 100
+batch_size = 100
+input_shape = X_train.shape[1:4]
+receptive_field = 3
+n_filters = 10
+n_neurons_connected = 50
+n_categories = 10
+
+eta_vals = np.logspace(-5, 1, 7)
+lmbd_vals = np.logspace(-5, 1, 7)
+
+

+









+ +

Final part

+ +

+ + +

CNN_keras = np.zeros((len(eta_vals), len(lmbd_vals)), dtype=object)
+        
+for i, eta in enumerate(eta_vals):
+    for j, lmbd in enumerate(lmbd_vals):
+        CNN = create_convolutional_neural_network_keras(input_shape, receptive_field,
+                                              n_filters, n_neurons_connected, n_categories,
+                                              eta, lmbd)
+        CNN.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=0)
+        scores = CNN.evaluate(X_test, Y_test)
+        
+        CNN_keras[i][j] = CNN
+        
+        print("Learning rate = ", eta)
+        print("Lambda = ", lmbd)
+        print("Test accuracy: %.3f" % scores[1])
+        print()
+
+

+









+ +

Final visualization

+ +

+ + +

# visual representation of grid search
+# uses seaborn heatmap, could probably do this in matplotlib
+import seaborn as sns
+
+sns.set()
+
+train_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+test_accuracy = np.zeros((len(eta_vals), len(lmbd_vals)))
+
+for i in range(len(eta_vals)):
+    for j in range(len(lmbd_vals)):
+        CNN = CNN_keras[i][j]
+
+        train_accuracy[i][j] = CNN.evaluate(X_train, Y_train)[1]
+        test_accuracy[i][j] = CNN.evaluate(X_test, Y_test)[1]
+
+        
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(train_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Training Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+fig, ax = plt.subplots(figsize = (10, 10))
+sns.heatmap(test_accuracy, annot=True, ax=ax, cmap="viridis")
+ax.set_title("Test Accuracy")
+ax.set_ylabel("$\eta$")
+ax.set_xlabel("$\lambda$")
+plt.show()
+
+

+









+ +

Recurrent neural networks: Overarching view

+ +

+Till now our focus has been, including convolutional neural networks +as well, on feedforward neural networks. The output or the activations +flow only in one direction, from the input layer to the output layer. + +

+A recurrent neural network (RNN) looks very much like a feedforward +neural network, except that it also has connections pointing +backward. + +

+RNNs are used to analyze time series data such as stock prices, and +tell you when to buy or sell. In autonomous driving systems, they can +anticipate car trajectories and help avoid accidents. More generally, +they can work on sequences of arbitrary lengths, rather than on +fixed-sized inputs like all the nets we have discussed so far. For +example, they can take sentences, documents, or audio samples as +input, making them extremely useful for natural language processing +systems such as automatic translation and speech-to-text. + +

+









+ +

Set up of an RNN

+ +

+The figure here displays a simple example of an RNN, with inputs \( x_t \) +at a given time \( t \) and outputs \( y_t \). Introducing time as a variable +offers an intutitive way of understanding these networks. In addition +to the inputs \( x_t \), the layer at a time \( t \) receives also as input +the output from the previous layer \( t-1 \), that is \( y_{t1} \). + +

+This means also that we need to have weights that link both the inputs +\( x_t \) to the outputs \( y_t \) as well as weights that link the output +from the previous time \( y_{t-1} \) and \( y_t \). The figure here shows an +example of a simple RNN. + +

+









+ +

Solving differential equations and eigenvalue problems with RNNs

+ +

+In our discussions of ordinary differential equations and partial +differential equations using neural networks. Here we will discuss how +we can solve say ordinary differential equations and eigenvalue +problems using RNNs. Eigenvalue problems can be solved using RNNs by +rewriting such a problems as a non-linear differential equation. + +

+Instead of starting with a well-known ordinary differential equation, +we start directly with an eigenvaule problem. + +

+









+ +

Long-Short Time Memory

+ +

+Discussions about dynamic unrolling through time. discuss memory cells, input and output + +

+









+ +

Autoencoders: Overarching view

+ +

+Autoencoders are artificial neural networks capable of learning +efficient representations of the input data (these representations are called codings) without +any supervision (i.e., the training set is unlabeled). These codings +typically have a much lower dimensionality than the input data, making +autoencoders useful for dimensionality reduction. + +

+More importantly, autoencoders act as powerful feature detectors, and +they can be used for unsupervised pretraining of deep neural networks. + +

+Lastly, they are capable of randomly generating new data that looks +very similar to the training data; this is called a generative +model. For example, you could train an autoencoder on pictures of +faces, and it would then be able to generate new faces. Surprisingly, +autoencoders work by simply learning to copy their inputs to their +outputs. This may sound like a trivial task, but we will see that +constraining the network in various ways can make it rather +difficult. For example, you can limit the size of the internal +representation, or you can add noise to the inputs and train the +network to recover the original inputs. These constraints prevent the +autoencoder from trivially copying the inputs directly to the outputs, +which forces it to learn efficient ways of representing the data. In +short, the codings are byproducts of the autoencoder’s attempt to +learn the identity function under some constraints. + +

+









+ +

Simple examples of Autoencoders

+ +

+ + + + +

+ © 1999-2020, Morten Hjorth-Jensen. Released under CC Attribution-NonCommercial 4.0 license +
+ + + + + +