Files
FYS-STK4155/doc/LectureNotes/_build/html/project2.html
T
Morten Hjorth-Jensen d6bb9335d0 update lecture notes
2024-10-28 06:15:26 +01:00

827 lines
42 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Project 2 on Machine Learning, deadline November 4 (Midnight) &#8212; Applied Data Analysis and Machine Learning</title>
<link href="_static/css/theme.css" rel="stylesheet">
<link href="_static/css/index.ff1ffe594081f20da1ef19478df9384b.css" rel="stylesheet">
<link rel="stylesheet"
href="_static/vendor/fontawesome/5.13.0/css/all.min.css">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin
href="_static/vendor/fontawesome/5.13.0/webfonts/fa-brands-400.woff2">
<link rel="stylesheet" type="text/css" href="_static/pygments.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-book-theme.css?digest=c3fdc42140077d1ad13ad2f1588a4309" />
<link rel="stylesheet" type="text/css" href="_static/togglebutton.css" />
<link rel="stylesheet" type="text/css" href="_static/copybutton.css" />
<link rel="stylesheet" type="text/css" href="_static/mystnb.css" />
<link rel="stylesheet" type="text/css" href="_static/sphinx-thebe.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-main.c949a650a448cc0ae9fd3441c0e17fb0.css" />
<link rel="stylesheet" type="text/css" href="_static/panels-variables.06eb56fa6e07937060861dad626602ad.css" />
<link rel="preload" as="script" href="_static/js/index.be7d3bbb2ef33a8344ce.js">
<script data-url_root="./" id="documentation_options" src="_static/documentation_options.js"></script>
<script src="_static/jquery.js"></script>
<script src="_static/underscore.js"></script>
<script src="_static/doctools.js"></script>
<script src="_static/clipboard.min.js"></script>
<script src="_static/copybutton.js"></script>
<script>let toggleHintShow = 'Click to show';</script>
<script>let toggleHintHide = 'Click to hide';</script>
<script>let toggleOpenOnPrint = 'true';</script>
<script src="_static/togglebutton.js"></script>
<script>var togglebuttonSelector = '.toggle, .admonition.dropdown, .tag_hide_input div.cell_input, .tag_hide-input div.cell_input, .tag_hide_output div.cell_output, .tag_hide-output div.cell_output, .tag_hide_cell.cell, .tag_hide-cell.cell';</script>
<script src="_static/sphinx-book-theme.d59cb220de22ca1c485ebbdc042f0030.js"></script>
<script>const THEBE_JS_URL = "https://unpkg.com/thebe@0.8.2/lib/index.js"
const thebe_selector = ".thebe,.cell"
const thebe_selector_input = "pre"
const thebe_selector_output = ".output, .cell_output"
</script>
<script async="async" src="_static/sphinx-thebe.js"></script>
<script>window.MathJax = {"options": {"processHtmlClass": "tex2jax_process|mathjax_process|math|output_area"}}</script>
<script defer="defer" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
<link rel="index" title="Index" href="genindex.html" />
<link rel="search" title="Search" href="search.html" />
<link rel="prev" title="Project 1 on Machine Learning, deadline October 7 (midnight), 2024" href="project1.html" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="None">
<!-- Google Analytics -->
</head>
<body data-spy="scroll" data-target="#bd-toc-nav" data-offset="80">
<div class="container-fluid" id="banner"></div>
<div class="container-xl">
<div class="row">
<div class="col-12 col-md-3 bd-sidebar site-navigation show" id="site-navigation">
<div class="navbar-brand-box">
<a class="navbar-brand text-wrap" href="index.html">
<!-- `logo` is deprecated in Sphinx 4.0, so remove this when we stop supporting 3 -->
<img src="_static/logo.png" class="logo" alt="logo">
<h1 class="site-logo" id="site-title">Applied Data Analysis and Machine Learning</h1>
</a>
</div><form class="bd-search d-flex align-items-center" action="search.html" method="get">
<i class="icon fas fa-search"></i>
<input type="search" class="form-control" name="q" id="search-input" placeholder="Search this book..." aria-label="Search this book..." autocomplete="off" >
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main">
<div class="bd-toc-item active">
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="intro.html">
Applied Data Analysis and Machine Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
About the course
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="schedule.html">
Teaching schedule with links to material
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="teachers.html">
Teachers and Grading
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="textbooks.html">
Textbooks
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Review of Statistics with Resampling Techniques and Linear Algebra
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="statistics.html">
1. Elements of Probability Theory and Statistical Data Analysis
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="linalg.html">
2. Linear Algebra, Handling of Arrays and more Python Features
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
From Regression to Support Vector Machines
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter1.html">
3. Linear Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter2.html">
4. Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter3.html">
5. Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter4.html">
6. Logistic Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapteroptimization.html">
7. Optimization, the central part of any Machine Learning algortithm
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter5.html">
8. Support Vector Machines, overarching aims
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Decision Trees, Ensemble Methods and Boosting
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter6.html">
9. Decision trees, overarching aims
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter7.html">
10. Ensemble Methods: From a Single Tree to Many Trees and Extreme Boosting, Meet the Jungle of Methods
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Dimensionality Reduction
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter8.html">
11. Basic ideas of the Principal Component Analysis (PCA)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="clustering.html">
12. Clustering and Unsupervised Learning
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Deep Learning Methods
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="chapter9.html">
13. Neural networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter10.html">
14. Building a Feed Forward Neural Network
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter11.html">
15. Solving Differential Equations with Deep Learning
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter12.html">
16. Convolutional Neural Networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="chapter13.html">
17. Recurrent neural networks: Overarching view
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Weekly material, notes and exercises
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek34.html">
Exercises week 34
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week34.html">
Week 34: Introduction to the course, Logistics and Practicalities
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek35.html">
Exercises week 35
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week35.html">
Week 35: From Ordinary Linear Regression to Ridge and Lasso Regression
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek36.html">
Exercises week 36
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week36.html">
Week 36: Linear Regression and Statistical interpretations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek37.html">
Exercises week 37
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week37.html">
Week 37: Statistical interpretations and Resampling Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek38.html">
Exercises week 38
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week38.html">
Week 38: Logistic Regression and Optimization
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek39.html">
Exercises week 39
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week39.html">
Week 39: Optimization and Gradient Methods
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week40.html">
Week 40: Gradient descent methods (continued) and start Neural networks
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek41.html">
Exercises week 41
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week41.html">
Week 41 Neural networks and constructing a neural network code
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek42.html">
Exercises week 42
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week42.html">
Week 42 Constructing a Neural Network code with examples
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="additionweek42.html">
Exercises Week 42: Logistic Regression and Optimization, reminders from week 38 and week 40
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week43.html">
Week 43: Deep Learning: Constructing a Neural Network code and solving differential equations
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="exercisesweek43.html">
Exercises week 43
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="week44.html">
Week 44, Convolutional Neural Networks (CNN)
</a>
</li>
</ul>
<p aria-level="2" class="caption" role="heading">
<span class="caption-text">
Projects
</span>
</p>
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="project1.html">
Project 1 on Machine Learning, deadline October 7 (midnight), 2024
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
Project 2 on Machine Learning, deadline November 4 (Midnight)
</a>
</li>
</ul>
</div>
</nav> <!-- To handle the deprecated key -->
<div class="navbar_extra_footer">
Powered by <a href="https://jupyterbook.org">Jupyter Book</a>
</div>
</div>
<main class="col py-md-3 pl-md-4 bd-content overflow-auto" role="main">
<div class="topbar container-xl fixed-top">
<div class="topbar-contents row">
<div class="col-12 col-md-3 bd-topbar-whitespace site-navigation show"></div>
<div class="col pl-md-4 topbar-main">
<button id="navbar-toggler" class="navbar-toggler ml-0" type="button" data-toggle="collapse"
data-toggle="tooltip" data-placement="bottom" data-target=".site-navigation" aria-controls="navbar-menu"
aria-expanded="true" aria-label="Toggle navigation" aria-controls="site-navigation"
title="Toggle navigation" data-toggle="tooltip" data-placement="left">
<i class="fas fa-bars"></i>
<i class="fas fa-arrow-left"></i>
<i class="fas fa-arrow-up"></i>
</button>
<div class="dropdown-buttons-trigger">
<button id="dropdown-buttons-trigger" class="btn btn-secondary topbarbtn" aria-label="Download this page"><i
class="fas fa-download"></i></button>
<div class="dropdown-buttons">
<!-- ipynb file if we had a myst markdown file -->
<!-- Download raw file -->
<a class="dropdown-buttons" href="_sources/project2.ipynb"><button type="button"
class="btn btn-secondary topbarbtn" title="Download source file" data-toggle="tooltip"
data-placement="left">.ipynb</button></a>
<!-- Download PDF via print -->
<button type="button" id="download-print" class="btn btn-secondary topbarbtn" title="Print to PDF"
onclick="printPdf(this)" data-toggle="tooltip" data-placement="left">.pdf</button>
</div>
</div>
<!-- Source interaction buttons -->
<!-- Full screen (wrap in <a> to have style consistency -->
<a class="full-screen-button"><button type="button" class="btn btn-secondary topbarbtn" data-toggle="tooltip"
data-placement="bottom" onclick="toggleFullScreen()" aria-label="Fullscreen mode"
title="Fullscreen mode"><i
class="fas fa-expand"></i></button></a>
<!-- Launch buttons -->
</div>
<!-- Table of contents -->
<div class="d-none d-md-block col-md-2 bd-toc show noprint">
<div class="tocsection onthispage pt-5 pb-3">
<i class="fas fa-list"></i> Contents
</div>
<nav id="bd-toc-nav" aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
Classification and Regression, from linear and logistic regression to neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step">
Part a): Write your own Stochastic Gradient Descent code, first step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b-writing-your-own-neural-network-code">
Part b): Writing your own Neural Network code
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-testing-different-activation-functions">
Part c): Testing different activation functions
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-classification-analysis-using-neural-networks">
Part d): Classification analysis using neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e-write-your-logistic-regression-code-final-step">
Part e): Write your Logistic Regression code, final step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-f-critical-evaluation-of-the-various-algorithms">
Part f) Critical evaluation of the various algorithms
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#background-literature">
Background literature
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div id="main-content" class="row">
<div class="col-12 col-md-9 pl-md-3 pr-md-0">
<!-- Table of contents that is only displayed when printing the page -->
<div id="jb-print-docs-body" class="onlyprint">
<h1>Project 2 on Machine Learning, deadline November 4 (Midnight)</h1>
<!-- Table of contents -->
<div id="print-main-content">
<div id="jb-print-toc">
<div>
<h2> Contents </h2>
</div>
<nav aria-label="Page">
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
Classification and Regression, from linear and logistic regression to neural networks
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step">
Part a): Write your own Stochastic Gradient Descent code, first step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-b-writing-your-own-neural-network-code">
Part b): Writing your own Neural Network code
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-c-testing-different-activation-functions">
Part c): Testing different activation functions
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-d-classification-analysis-using-neural-networks">
Part d): Classification analysis using neural networks
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-e-write-your-logistic-regression-code-final-step">
Part e): Write your Logistic Regression code, final step
</a>
</li>
<li class="toc-h3 nav-item toc-entry">
<a class="reference internal nav-link" href="#part-f-critical-evaluation-of-the-various-algorithms">
Part f) Critical evaluation of the various algorithms
</a>
</li>
</ul>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#background-literature">
Background literature
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#introduction-to-numerical-projects">
Introduction to numerical projects
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#format-for-electronic-delivery-of-report-and-programs">
Format for electronic delivery of report and programs
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div>
<!-- HTML file automatically generated from DocOnce source (https://github.com/doconce/doconce/)
doconce format html Project2.do.txt -->
<!-- dom:TITLE: Project 2 on Machine Learning, deadline November 4 (Midnight) --><div class="tex2jax_ignore mathjax_ignore section" id="project-2-on-machine-learning-deadline-november-4-midnight">
<h1>Project 2 on Machine Learning, deadline November 4 (Midnight)<a class="headerlink" href="#project-2-on-machine-learning-deadline-november-4-midnight" title="Permalink to this headline"></a></h1>
<p><strong><a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a></strong>, Department of Physics, University of Oslo, Norway</p>
<p>Date: <strong>Oct 8, 2024</strong></p>
<p>Copyright 1999-2024, <a class="reference external" href="http://www.uio.no/studier/emner/matnat/fys/FYS3155/index-eng.html">Data Analysis and Machine Learning FYS-STK3155/FYS4155</a>. Released under CC Attribution-NonCommercial 4.0 license</p>
<div class="section" id="classification-and-regression-from-linear-and-logistic-regression-to-neural-networks">
<h2>Classification and Regression, from linear and logistic regression to neural networks<a class="headerlink" href="#classification-and-regression-from-linear-and-logistic-regression-to-neural-networks" title="Permalink to this headline"></a></h2>
<p>The main aim of this project is to study both classification and
regression problems by developing our own feed-forward neural network
(FFNN) code. We can reuse the regression algorithms studied in project</p>
<ol class="simple">
<li><p>We will also include logistic regression for classification
problems and write our own FFNN code for studying both regression and
classification problems. The codes developed in project 1, including
bootstrap <strong>and/or</strong> cross-validation as well as the computation of the
mean-squared error and/or the <span class="math notranslate nohighlight">\(R2\)</span> or the accuracy score
(classification problems) functions can also be utilized in the
present analysis.</p></li>
</ol>
<p>The data sets that we propose here are (the default sets)</p>
<ul class="simple">
<li><p>Regression (fitting a continuous function). In this part you will need to bring back your results from project 1 and compare these with what you get from your Neural Network code to be developed here. The data sets could be</p></li>
</ul>
<p>a. A simple one-dimensional function or the Franke function or the terrain data from project 1, or data sets your propose. It could be a simpler function than the Franke function. We recommend testing a simpler function (see below). But if you wish to try more complex function, feel free to do so.</p>
<ul class="simple">
<li><p>Classification. Here you will also need to develop a Logistic regression code that you will use to compare with the Neural Network code. The data set we propose are the so-called <a class="reference external" href="https://www.kaggle.com/uciml/breast-cancer-wisconsin-data">Wisconsin Breat Cancer Data</a> data set of images representing various features of tumors. A longer explanation with links to the scientific literature can be found at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/Breast+Cancer+Wisconsin+%28Diagnostic%29">Machine Learning repository of the University of California at Irvine</a>. Feel free to consult this site and the pertinent literature.</p></li>
</ul>
<p>You can find more information about this at the <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html">Scikit-Learn site</a> or at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)">University of California at Irvine</a>.</p>
<p>However, if you would like to study other data sets, feel free to
propose other sets. What we list here are mere suggestions from our
side. If you opt for another data set, consider using a set which has
been studied in the scientific literature. This makes it easier for
you to compare and analyze your results. Comparing with existing
results from the scientific literature is also an essential element of
the scientific discussion. The University of California at Irvine
with its Machine Learning repository at
<a class="reference external" href="https://archive.ics.uci.edu/ml/index.php">https://archive.ics.uci.edu/ml/index.php</a> is an excellent site to
look up for examples and
inspiration. <a class="reference external" href="https://www.kaggle.com/">Kaggle.com</a> is an equally
interesting site. Feel free to explore these sites.</p>
<p>We will start with a regression problem and we will reuse our codes from project 1 starting with writing our own Stochastic Gradient Descent (SGD) code.</p>
<div class="section" id="part-a-write-your-own-stochastic-gradient-descent-code-first-step">
<h3>Part a): Write your own Stochastic Gradient Descent code, first step<a class="headerlink" href="#part-a-write-your-own-stochastic-gradient-descent-code-first-step" title="Permalink to this headline"></a></h3>
<p>In order to get started, we will now replace in our standard ordinary
least squares (OLS) and Ridge regression codes (from project 1) the
matrix inversion algorithm with our own gradient descent (GD) and SGD
codes. You can use the Franke function or the terrain data from
project 1. <strong>However, we recommend using a simpler function like</strong>
<span class="math notranslate nohighlight">\(f(x)=a_0+a_1x+a_2x^2\)</span> or higher-order one-dimensional polynomials.
You can obviously test your final codes against for example the Franke
function.</p>
<p>The exercise set for week 41 should help in solving this part of the project.</p>
<p>You should include in your analysis of the GD and SGD codes the following elements</p>
<ol class="simple">
<li><p>A plain gradient descent with a fixed learning rate (you will need to tune it) using the analytical expression for the gradient.</p></li>
<li><p>Add momentum to the plain GD code and compare convergence with a fixed learning rate (you may need to tune the learning rate). Keep using the analytical expression for the gradient.</p></li>
<li><p>Repeat these steps for stochastic gradient descent with mini batches and a given number of epochs. Use a tunable learning rate as discussed in the lectures from weeks 39 and 40. Discuss the results as functions of the various parameters (size of batches, number of epochs etc). Use the analytical gradient.</p></li>
<li><p>Implement the Adagrad method in order to tune the learning rate. Do this with and without momentum for plain gradient descent and SGD.</p></li>
<li><p>Add RMSprop and Adam to your library of methods for tuning the learning rate.</p></li>
</ol>
<p>The lecture notes from <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week39/html/week39.html">weeks 39 and 40 contain more
details</a> and code examples. Feel free to use these examples.</p>
<ol class="simple">
<li><p>Replace thereafter your analytical gradient with either <strong>Autograd</strong> or <strong>JAX</strong></p></li>
</ol>
<p><strong>Feel free to use codes on these methods from the lecture notes from week 39 and week 40</strong>.</p>
<p>In summary, you should
perform an analysis of the results for OLS and Ridge regression as
function of the chosen learning rates, the number of mini-batches and
epochs as well as algorithm for scaling the learning rate. You can
also compare your own results with those that can be obtained using
for example <strong>Scikit-Learn</strong>s various SGD options. Discuss your
results. For Ridge regression you need now to study the results as functions of the hyper-parameter <span class="math notranslate nohighlight">\(\lambda\)</span> and
the learning rate <span class="math notranslate nohighlight">\(\eta\)</span>. Discuss your results.</p>
<p>You will need your SGD code for the setup of the Neural Network and
Logistic Regression codes. You will find the Python <a class="reference external" href="https://seaborn.pydata.org/generated/seaborn.heatmap.html">Seaborn
package</a>
useful when plotting the results as function of the learning rate
<span class="math notranslate nohighlight">\(\eta\)</span> and the hyper-parameter <span class="math notranslate nohighlight">\(\lambda\)</span> when you use Ridge
regression. Since you will use different gradient descent methods, you can also add Lasse regression. This is however optional. How to code Lasso regression is discussed in the lecture notes from week 40.</p>
<p>We recommend reading chapter 8 on optimization from the textbook of Goodfellow, Bengio and Courville at <a class="reference external" href="https://www.deeplearningbook.org/">https://www.deeplearningbook.org/</a>. This chapter contains many useful insights and discussions on the optimization part of machine learning.</p>
</div>
<div class="section" id="part-b-writing-your-own-neural-network-code">
<h3>Part b): Writing your own Neural Network code<a class="headerlink" href="#part-b-writing-your-own-neural-network-code" title="Permalink to this headline"></a></h3>
<p>Your aim now, and this is the central part of this project, is to
write your own Feed Forward Neural Network code implementing the back
propagation algorithm discussed in the lecture slides from <a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week41/ipynb/week41.ipynb">week 41</a> and
<a class="reference external" href="https://compphysics.github.io/MachineLearning/doc/pub/week42/ipynb/week42.ipynb">week 42</a>.</p>
<p>We will focus on a regression problem first and study either the simple second-order polynomial from part a) or the
Franke function or terrain data (or both or other data sets) from
project 1.</p>
<p>Discuss again your choice of cost function.</p>
<p>Write an FFNN code for regression with a flexible number of hidden
layers and nodes using the Sigmoid function as activation function for
the hidden layers. Initialize the weights using a normal
distribution. How would you initialize the biases? And which
activation function would you select for the final output layer?</p>
<p>Train your network and compare the results with those from your OLS and Ridge Regression codes from project 1 if you use the Franke function or the terrain data.
You should test your results against a similar code using <strong>Scikit-Learn</strong> (see the examples in the above lecture notes from weeks 41 and 42) or <strong>tensorflow/keras</strong> or <strong>Pytorch</strong> (for Pytorch, see Raschka et al.s text chapters 12 and 13).</p>
<p>Comment your results and give a critical discussion of the results
obtained with the Linear Regression code and your own Neural Network
code.<br />
Make an analysis of the regularization parameters and the learning rates employed to find the optimal MSE and <span class="math notranslate nohighlight">\(R2\)</span> scores.</p>
<p>A useful reference on the back progagation algorithm is Nielsens book at <a class="reference external" href="http://neuralnetworksanddeeplearning.com/">http://neuralnetworksanddeeplearning.com/</a>. It is an excellent
read.</p>
</div>
<div class="section" id="part-c-testing-different-activation-functions">
<h3>Part c): Testing different activation functions<a class="headerlink" href="#part-c-testing-different-activation-functions" title="Permalink to this headline"></a></h3>
<p>You should now also test different activation functions for the hidden layers. Try out the Sigmoid, the RELU and the Leaky RELU functions and discuss your results. You may also study the way you initialize your weights and biases.</p>
</div>
<div class="section" id="part-d-classification-analysis-using-neural-networks">
<h3>Part d): Classification analysis using neural networks<a class="headerlink" href="#part-d-classification-analysis-using-neural-networks" title="Permalink to this headline"></a></h3>
<p>With a well-written code it should now be easy to change the
activation function for the output layer.</p>
<p>Here we will change the cost function for our neural network code
developed in parts b) and c) in order to perform a classification analysis.</p>
<p>We will here study the Wisconsin Breast Cancer data set. This is a typical binary classification problem with just one single output, either True or Fale, <span class="math notranslate nohighlight">\(0\)</span> or <span class="math notranslate nohighlight">\(1\)</span> etc.
You find more information about this at the <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html">Scikit-Learn
site</a> or at the <a class="reference external" href="https://archive.ics.uci.edu/ml/datasets/breast+cancer+wisconsin+(original)">University of California
at Irvine</a>.</p>
<p>To measure the performance of our classification problem we use the
so-called <em>accuracy</em> score. The accuracy is as you would expect just
the number of correctly guessed targets <span class="math notranslate nohighlight">\(t_i\)</span> divided by the total
number of targets, that is</p>
<div class="math notranslate nohighlight">
\[
\text{Accuracy} = \frac{\sum_{i=1}^n I(t_i = y_i)}{n} ,
\]</div>
<p>where <span class="math notranslate nohighlight">\(I\)</span> is the indicator function, <span class="math notranslate nohighlight">\(1\)</span> if <span class="math notranslate nohighlight">\(t_i = y_i\)</span> and <span class="math notranslate nohighlight">\(0\)</span>
otherwise if we have a binary classification problem. Here <span class="math notranslate nohighlight">\(t_i\)</span>
represents the target and <span class="math notranslate nohighlight">\(y_i\)</span> the outputs of your FFNN code and <span class="math notranslate nohighlight">\(n\)</span> is simply the number of targets <span class="math notranslate nohighlight">\(t_i\)</span>.</p>
<p>Discuss your results and give a critical analysis of the various parameters, including hyper-parameters like the learning rates and the regularization parameter <span class="math notranslate nohighlight">\(\lambda\)</span> (as you did in Ridge Regression), various activation functions, number of hidden layers and nodes and activation functions.</p>
<p>As stated in the introduction, it can also be useful to study other
datasets.</p>
<p>Again, we strongly recommend that you compare your own neural Network
code for classification and pertinent results against a similar code using <strong>Scikit-Learn</strong> or <strong>tensorflow/keras</strong> or <strong>pytorch</strong>.</p>
</div>
<div class="section" id="part-e-write-your-logistic-regression-code-final-step">
<h3>Part e): Write your Logistic Regression code, final step<a class="headerlink" href="#part-e-write-your-logistic-regression-code-final-step" title="Permalink to this headline"></a></h3>
<p>Finally, we want to compare the FFNN code we have developed with
Logistic regression, that is we wish to compare our neural network
classification results with the results we can obtain with another
method.</p>
<p>Define your cost function and the design matrix before you start writing your code.
Write thereafter a Logistic regression code using your SGD algorithm. You can also use standard gradient descent in this case, with a learning rate as hyper-parameter.
Study the results as functions of the chosen learning rates.
Add also an <span class="math notranslate nohighlight">\(l_2\)</span> regularization parameter <span class="math notranslate nohighlight">\(\lambda\)</span>. Compare your results with those from your FFNN code as well as those obtained using <strong>Scikit-Learn</strong>s logistic regression functionality.</p>
<p>The weblink here <a class="reference external" href="https://medium.com/ai-in-plain-english/comparison-between-logistic-regression-and-neural-networks-in-classifying-digits-dc5e85cd93c3">https://medium.com/ai-in-plain-english/comparison-between-logistic-regression-and-neural-networks-in-classifying-digits-dc5e85cd93c3</a>compares logistic regression and FFNN using the so-called MNIST data set. You may find several useful hints and ideas from this article.</p>
</div>
<div class="section" id="part-f-critical-evaluation-of-the-various-algorithms">
<h3>Part f) Critical evaluation of the various algorithms<a class="headerlink" href="#part-f-critical-evaluation-of-the-various-algorithms" title="Permalink to this headline"></a></h3>
<p>After all these glorious calculations, you should now summarize the
various algorithms and come with a critical evaluation of their pros
and cons. Which algorithm works best for the regression case and which
is best for the classification case. These codes can also be part of
your final project 3, but now applied to other data sets.</p>
</div>
</div>
<div class="section" id="background-literature">
<h2>Background literature<a class="headerlink" href="#background-literature" title="Permalink to this headline"></a></h2>
<ol class="simple">
<li><p>The text of Michael Nielsen is highly recommended, see Nielsens book at <a class="reference external" href="http://neuralnetworksanddeeplearning.com/">http://neuralnetworksanddeeplearning.com/</a>. It is an excellent read.</p></li>
<li><p>Goodfellow, Bengio and Courville, Deep Learning at <a class="reference external" href="https://www.deeplearningbook.org/">https://www.deeplearningbook.org/</a>. Here we recommend chapters 6, 7 and 8</p></li>
<li><p>Raschka et al. at <a class="reference external" href="https://sebastianraschka.com/blog/2022/ml-pytorch-book.html">https://sebastianraschka.com/blog/2022/ml-pytorch-book.html</a>. Here we recommend chapters 11, 12 and 13.</p></li>
</ol>
</div>
<div class="section" id="introduction-to-numerical-projects">
<h2>Introduction to numerical projects<a class="headerlink" href="#introduction-to-numerical-projects" title="Permalink to this headline"></a></h2>
<p>Here follows a brief recipe and recommendation on how to write a report for each
project.</p>
<ul class="simple">
<li><p>Give a short description of the nature of the problem and the eventual numerical methods you have used.</p></li>
<li><p>Describe the algorithm you have used and/or developed. Here you may find it convenient to use pseudocoding. In many cases you can describe the algorithm in the program itself.</p></li>
<li><p>Include the source code of your program. Comment your program properly.</p></li>
<li><p>If possible, try to find analytic solutions, or known limits in order to test your program when developing the code.</p></li>
<li><p>Include your results either in figure form or in a table. Remember to label your results. All tables and figures should have relevant captions and labels on the axes.</p></li>
<li><p>Try to evaluate the reliabilty and numerical stability/precision of your results. If possible, include a qualitative and/or quantitative discussion of the numerical stability, eventual loss of precision etc.</p></li>
<li><p>Try to give an interpretation of you results in your answers to the problems.</p></li>
<li><p>Critique: if possible include your comments and reflections about the exercise, whether you felt you learnt something, ideas for improvements and other thoughts youve made when solving the exercise. We wish to keep this course at the interactive level and your comments can help us improve it.</p></li>
<li><p>Try to establish a practice where you log your work at the computerlab. You may find such a logbook very handy at later stages in your work, especially when you dont properly remember what a previous test version of your program did. Here you could also record the time spent on solving the exercise, various algorithms you may have tested or other topics which you feel worthy of mentioning.</p></li>
</ul>
</div>
<div class="section" id="format-for-electronic-delivery-of-report-and-programs">
<h2>Format for electronic delivery of report and programs<a class="headerlink" href="#format-for-electronic-delivery-of-report-and-programs" title="Permalink to this headline"></a></h2>
<p>The preferred format for the report is a PDF file. You can also use DOC or postscript formats or as an ipython notebook file. As programming language we prefer that you choose between C/C++, Fortran2008 or Python. The following prescription should be followed when preparing the report:</p>
<ul class="simple">
<li><p>Use Canvas to hand in your projects, log in at <a class="reference external" href="https://www.uio.no/english/services/it/education/canvas/">https://www.uio.no/english/services/it/education/canvas/</a> with your normal UiO username and password.</p></li>
<li><p>Upload <strong>only</strong> the report file or the link to your GitHub/GitLab or similar typo of repos! For the source code file(s) you have developed please provide us with your link to your GitHub/GitLab or similar domain. The report file should include all of your discussions and a list of the codes you have developed. Do not include library files which are available at the course homepage, unless you have made specific changes to them.</p></li>
<li><p>In your GitHub/GitLab or similar repository, please include a folder which contains selected results. These can be in the form of output from your code for a selected set of runs and input parameters.</p></li>
</ul>
<p>Finally,
we encourage you to collaborate. Optimal working groups consist of
2-3 students. You can then hand in a common report.</p>
</div>
</div>
<script type="text/x-thebe-config">
{
requestKernel: true,
binderOptions: {
repo: "binder-examples/jupyter-stacks-datascience",
ref: "master",
},
codeMirrorConfig: {
theme: "abcdef",
mode: "python"
},
kernelOptions: {
kernelName: "python3",
path: "./."
},
predefinedOutput: true
}
</script>
<script>kernelName = 'python3'</script>
</div>
<!-- Previous / next buttons -->
<div class='prev-next-area'>
<a class='left-prev' id="prev-link" href="project1.html" title="previous page">
<i class="fas fa-angle-left"></i>
<div class="prev-next-info">
<p class="prev-next-subtitle">previous</p>
<p class="prev-next-title">Project 1 on Machine Learning, deadline October 7 (midnight), 2024</p>
</div>
</a>
</div>
</div>
</div>
<footer class="footer">
<p>
By Morten Hjorth-Jensen<br/>
&copy; Copyright 2021.<br/>
</p>
</footer>
</main>
</div>
</div>
<script src="_static/js/index.be7d3bbb2ef33a8344ce.js"></script>
</body>
</html>