{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Autoencoders & GANs with PyTorch\n",
        "Xenors practice notebook. Run each cell and compare the output with the tutorial page.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Measure reconstruction error\n",
        "Reconstruction loss is useful for autoencoders but does not directly measure perceptual quality.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "import torch\n",
        "x=torch.tensor([[0.,1.],[1.,0.]])\n",
        "x_hat=torch.tensor([[.1,.8],[.9,.2]])\n",
        "print(torch.mean((x-x_hat)**2).item())\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\n0.025\n```\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "## Track generator and discriminator losses together\n",
        "GAN losses can look stable while samples collapse, so inspect generated outputs too.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {},
      "outputs": [],
      "source": [
        "history={'g':[1.2,1.0,.9],'d':[.7,.65,.62]}\n",
        "print('g_last',history['g'][-1],'d_last',history['d'][-1])\n"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "**Expected/checkpoint**\n",
        "```text\ng_last 0.9 d_last 0.62\n```\n"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python",
      "version": "3.x"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}