{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "mse-iris-intro",
      "metadata": {},
      "source": "# Aner: an Iris classifier with MSE\n\nUse an updated native Aner executable with loss selection support and the compatible VS Code extension **0.1.18**. Updating only the extension does not update the executable. See `docs/INSTALLATION.md` and `docs/VSCODE.md`. Run these cells in order, or choose **Run All**. The notebook uses shared native variables and trains a small CPU Float64 dense classifier using full batch SGD.\n\nThe classifier explicitly selects `loss: \"mse\"`. It computes the mean squared difference between softmax probabilities and one hot targets, averaged over all rows × classes. Initial training loss, optimization, final training loss, and evaluation use this same loss. The default when `loss` is omitted is `\"cross_entropy\"`; only these two exact strings are accepted.\n\nThe configuration and fitted model are separate values: `fit` creates a new fitted snapshot. Test rows never fit the standardizer. This example has no saved results; run the cells to produce your own.\n"
    },
    {
      "cell_type": "code",
      "id": "mse-iris-data",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": "import aner.dataset\nimport aner.nn\nimport aner.ml\n\nlet flowers = dataset.iris()\nlet split = flowers.split(test: 0.2, seed: 2026)\n"
    },
    {
      "cell_type": "markdown",
      "id": "mse-iris-topology-note",
      "metadata": {},
      "source": "## Define the topology and loss\n\nFour input features → eight dense units → tanh → three output logits. Layer dimensions are explicit and checked. The network initialization seed is separate from the data split seed. Keep the final Dense layer as raw logits: the classifier applies softmax internally for MSE.\n\nThe fit cell prints the final training MSE. The evaluation cell prints the selected loss, full training configuration, provenance, and held out results. The split, topology, epochs, and learning rate match the concise cross entropy example. Loss scales and gradients differ, so the numerical losses are not directly comparable and convergence can differ at the same rate.\n"
    },
    {
      "cell_type": "code",
      "id": "mse-iris-topology",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": "let network = nn.sequential(seed: 42)\n    .dense(inputs: 4, outputs: 8)\n    .tanh()\n    .dense(inputs: 8, outputs: 3)\nlet pipeline = ml.classifier(network, standardize: true, loss: \"mse\")\n"
    },
    {
      "cell_type": "code",
      "id": "mse-iris-fit",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": "let fitted = pipeline.fit(split.train(), epochs: 2000, rate: 0.1)\nprint(fitted.training_loss())\n"
    },
    {
      "cell_type": "code",
      "id": "mse-iris-evaluate",
      "metadata": {},
      "execution_count": null,
      "outputs": [],
      "source": "print(fitted.evaluate(split.test()).summary())\n"
    },
    {
      "cell_type": "markdown",
      "id": "mse-iris-provenance",
      "metadata": {},
      "source": "## Dataset attribution and experiment state\n\nFisher, R. (1936). **Iris** [Dataset]. UCI Machine Learning Repository. [DOI: 10.24432/C56C76](https://doi.org/10.24432/C56C76). Licensed under [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/). Original observations from `iris.data` are preserved; source class names map to IDs 0 to 2. UCI's documented alternative corrections are not applied. See `THIRD_PARTY_DATA.md` and `datasets/iris/README.md` supplied with the examples for retained notices, source variant, hashes, and transformation details.\n\nThis experiment selects a stratified training/test partition and fits feature standardization to training rows only. Reports retain the source hash, row IDs, and dataset attribution. The source above records the split seed; the dataset view does not retain that seed automatically. Keep the source together with results. A fixed seed does not promise bitwise equality across platforms.\n\nSaved outputs are historical content, not live variables or a model checkpoint. Restarting or reloading clears native state; **Run All** recreates it. Re running the fit cell trains a fresh snapshot from the same configuration. Live loss charts and a variable inspector are future work.\n"
    }
  ],
  "metadata": {
    "kernelspec": {
      "name": "aner",
      "display_name": "Aner",
      "language": "aner"
    },
    "language_info": {
      "name": "aner",
      "file_extension": ".aner",
      "mimetype": "text/x-aner"
    },
    "aner": {
      "status": "example",
      "execution_mode": "persistent-session"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}
