update exercises w38 and w39

This commit is contained in:
KarlHenrik
2025-09-10 12:14:32 +02:00
parent cee5f8e1f0
commit fbdf9c32f8
196 changed files with 23368 additions and 300 deletions
@@ -0,0 +1,85 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "b2bc44f6",
"metadata": {},
"source": [
"# Notebooks with MyST Markdown\n",
"\n",
"Jupyter Book also lets you write text-based notebooks using MyST Markdown.\n",
"See [the Notebooks with MyST Markdown documentation](https://jupyterbook.org/file-types/myst-notebooks.html) for more detailed instructions.\n",
"This page shows off a notebook written in MyST Markdown.\n",
"\n",
"## An example cell\n",
"\n",
"With MyST Markdown, you can define code cells with a directive like so:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4ddd8e91",
"metadata": {},
"outputs": [],
"source": [
"print(2 + 2)"
]
},
{
"cell_type": "markdown",
"id": "8e6cbd45",
"metadata": {},
"source": [
"When your book is built, the contents of any `{code-cell}` blocks will be\n",
"executed with your default Jupyter kernel, and their outputs will be displayed\n",
"in-line with the rest of your content.\n",
"\n",
"```{seealso}\n",
"Jupyter Book uses [Jupytext](https://jupytext.readthedocs.io/en/latest/) to convert text-based files to notebooks, and can support [many other text-based notebook files](https://jupyterbook.org/file-types/jupytext.html).\n",
"```\n",
"\n",
"## Create a notebook with MyST Markdown\n",
"\n",
"MyST Markdown notebooks are defined by two things:\n",
"\n",
"1. YAML metadata that is needed to understand if / how it should convert text files to notebooks (including information about the kernel needed).\n",
" See the YAML at the top of this page for example.\n",
"2. The presence of `{code-cell}` directives, which will be executed with your book.\n",
"\n",
"That's all that is needed to get started!\n",
"\n",
"## Quickly add YAML metadata for MyST Notebooks\n",
"\n",
"If you have a markdown file and you'd like to quickly add YAML metadata to it, so that Jupyter Book will treat it as a MyST Markdown Notebook, run the following command:\n",
"\n",
"```\n",
"jupyter-book myst init path/to/markdownfile.md\n",
"```"
]
}
],
"metadata": {
"jupytext": {
"formats": "md:myst",
"text_representation": {
"extension": ".md",
"format_name": "myst",
"format_version": 0.13,
"jupytext_version": "1.11.5"
}
},
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"source_map": [
13,
25,
27
]
},
"nbformat": 4,
"nbformat_minor": 5
}
@@ -0,0 +1,122 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Content with notebooks\n",
"\n",
"You can also create content with Jupyter Notebooks. This means that you can include\n",
"code blocks and their outputs in your book.\n",
"\n",
"## Markdown + notebooks\n",
"\n",
"As it is markdown, you can embed images, HTML, etc into your posts!\n",
"\n",
"![](https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg)\n",
"\n",
"You can also $add_{math}$ and\n",
"\n",
"$$\n",
"math^{blocks}\n",
"$$\n",
"\n",
"or\n",
"\n",
"$$\n",
"\\begin{aligned}\n",
"\\mbox{mean} la_{tex} \\\\ \\\\\n",
"math blocks\n",
"\\end{aligned}\n",
"$$\n",
"\n",
"But make sure you \\$Escape \\$your \\$dollar signs \\$you want to keep!\n",
"\n",
"## MyST markdown\n",
"\n",
"MyST markdown works in Jupyter Notebooks as well. For more information about MyST markdown, check\n",
"out [the MyST guide in Jupyter Book](https://jupyterbook.org/content/myst.html),\n",
"or see [the MyST markdown documentation](https://myst-parser.readthedocs.io/en/latest/).\n",
"\n",
"## Code blocks and outputs\n",
"\n",
"Jupyter Book will also embed your code blocks and output in your book.\n",
"For example, here's some sample Matplotlib code:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from matplotlib import rcParams, cycler\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"plt.ion()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Fixing random state for reproducibility\n",
"np.random.seed(19680801)\n",
"\n",
"N = 10\n",
"data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]\n",
"data = np.array(data).T\n",
"cmap = plt.cm.coolwarm\n",
"rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))\n",
"\n",
"\n",
"from matplotlib.lines import Line2D\n",
"custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),\n",
" Line2D([0], [0], color=cmap(.5), lw=4),\n",
" Line2D([0], [0], color=cmap(1.), lw=4)]\n",
"\n",
"fig, ax = plt.subplots(figsize=(10, 5))\n",
"lines = ax.plot(data)\n",
"ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"There is a lot more that you can do with outputs (such as including interactive outputs)\n",
"with your book. For more information about this, see [the Jupyter Book documentation](https://jupyterbook.org)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
@@ -245,9 +245,13 @@
"id": "831db06c",
"metadata": {},
"source": [
"**a)** Show that you can rewrite this in terms of a term which contains the variance of the model itself (the so-called variance term), a\n",
"term which measures the deviation from the true data and the mean value of the model (the bias term) and finally the variance of the noise Note that in order to be able to evaluate the bias them, you will need to approximate the function $f$ with the model ${\\bf y}$.\n",
"show that\n"
"**a)** Show that you can rewrite this into an expression which contains\n",
"\n",
"- the variance of the model (the variance term)\n",
"- the expected deviation of the mean of the model from the true data (the bias term)\n",
"- the variance of the noise\n",
"\n",
"In other words, show that:\n"
]
},
{
@@ -403,6 +407,8 @@
"# X = ...\n",
"# X_train, X_test, y_train, y_test = ...\n",
"#\n",
"# #this is where you fit your model on the sampled data\n",
"#\n",
"# predictions[b, :] =\n",
"# targets[b, :] =\n",
"#\n",
@@ -418,7 +424,7 @@
"source": [
"**e)** Discuss the bias-variance trade-off as function of your model complexity (the degree of the polynomial).\n",
"\n",
"**f)** Compute and discuss the bias and variance as function of the number of data points (choose a suitable polynomial degree to show something interesiting).\n"
"**f)** Compute and discuss the bias and variance as function of the number of data points (choose a suitable polynomial degree to show something interesting).\n"
]
},
{
@@ -56,7 +56,7 @@
"source": [
"We require all projects to be formatted as proper scientific reports, and this includes using LaTeX for typesetting. We strongly recommend that you use the online LaTeX editor Overleaf, as it is much easier to start using, and has excellent support for collaboration.\n",
"\n",
"**a)** Create an account on Overleaf.com\n",
"**a)** Create an account on Overleaf.com, or log in using SSO with your UiO email.\n",
"\n",
"**b)** Download [this](https://github.com/CompPhysics/MachineLearning/blob/master/doc/LectureNotes/data/FYS_STK_Template.zip) template project.\n",
"\n",
@@ -67,18 +67,6 @@
"**e)** Look at the provided example of an earlier project, found at <https://github.com/CompPhysics/MachineLearning/blob/master/doc/Projects/ReportExample/ReportExampleDanielBH.pdf>\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "338b2ee1",
"metadata": {
"vscode": {
"languageId": "plaintext"
}
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"id": "ec36f4c3",
@@ -130,7 +118,7 @@
"id": "2f512b59",
"metadata": {},
"source": [
"## Exercise 4: Making the code avaliable and presentable\n"
"## Exercise 4: Making the code available and presentable\n"
]
},
{