{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2d079df5-f984-4616-b4f1-44eff727e9bb",
   "metadata": {},
   "source": [
    "## 提示词\n",
    "\n",
    "``` \n",
    "任务：绘制学习曲线。给我Python代码，以实现绘制学习曲线的功能。学习曲线的形状是先平缓（代表投入很多学习但进度很慢），然后快速增加，然后又开始趋于平缓的S型曲线。下面是该学习曲线图上的文字：\n",
    "Learning curve\n",
    "Plateau\n",
    "you did it!\n",
    "Performance\n",
    "Steep acceleration\n",
    "Slow beginning\n",
    "Number of trials or attempts at learning\n",
    "注意：“Number of trials or attempts at learning”应当从0开始，而“Performance”要以百分比表示，适当调整图片上文字的位置（尤其是“Slow beginning”），避免被曲线遮挡\n",
    "```\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a1676dca-9ef4-4e4a-a2f9-02103e1fb5c1",
   "metadata": {},
   "source": [
    "## LLM输出代码与绘制结果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "8a943ea5-843c-4c92-8586-f85e19d30cf6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 75372 characters]",
      "text/plain": [
       "<Figure size 1000x700 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "from scipy.special import expit  # Sigmoid函数\n",
    "\n",
    "# 设置中文字体支持（如果需要）\n",
    "plt.rcParams['font.sans-serif'] = ['SimHei', 'DejaVu Sans']\n",
    "plt.rcParams['axes.unicode_minus'] = False\n",
    "\n",
    "def generate_learning_curve():\n",
    "    \"\"\"\n",
    "    生成模拟的学习曲线数据\n",
    "    \"\"\"\n",
    "    # x轴：学习尝试次数或时间点 (从0开始)\n",
    "    x = np.linspace(0, 20, 400)  # 调整范围从0到20，更符合\"trials/attempts\"的含义\n",
    "    \n",
    "    # 使用调整后的Sigmoid函数来模拟学习曲线\n",
    "    # 将x进行缩放和平移，使其适合sigmoid函数的输入范围\n",
    "    # Sigmoid函数输入通常在[-6, 6]左右变化较大，我们将其映射到[0, 20]\n",
    "    x_scaled = (x - 10) * 0.6  # 中心在10，缩放0.6倍，使曲线在中间陡峭\n",
    "    \n",
    "    y = expit(x_scaled)  # y值在[0, 1]之间\n",
    "    \n",
    "    # 将y值转换为百分比 [0%, 100%]\n",
    "    y_percentage = y * 100\n",
    "\n",
    "    return x, y_percentage\n",
    "\n",
    "def plot_learning_curve():\n",
    "    \"\"\"\n",
    "    绘制学习曲线，并添加标注\n",
    "    \"\"\"\n",
    "    x, y = generate_learning_curve()\n",
    "    \n",
    "    fig, ax = plt.subplots(figsize=(10, 7))\n",
    "    \n",
    "    ax.plot(x, y, label='Learning Curve', color='blue', linewidth=2)\n",
    "    \n",
    "    # 添加标题和轴标签\n",
    "    ax.set_title('Learning Curve', fontsize=16, fontweight='bold')\n",
    "    ax.set_xlabel('Number of trials or attempts at learning', fontsize=12)\n",
    "    ax.set_ylabel('Performance (%)', fontsize=12)  # 修改Y轴标签为百分比\n",
    "    \n",
    "    # 设置网格\n",
    "    ax.grid(True, linestyle='--', alpha=0.6)\n",
    "    \n",
    "    # Y轴设置为百分比格式\n",
    "    ax.yaxis.set_major_formatter(plt.FuncFormatter(lambda y, _: '{:.0f}%'.format(y)))\n",
    "    ax.set_ylim(0, 100)  # Y轴范围从0%到100%\n",
    "    ax.set_xlim(0, max(x))  # X轴范围从0开始\n",
    "    \n",
    "    # 添加标注 - 调整位置避免遮挡\n",
    "    # 1. Slow beginning (左下部分，x接近0，文字放在曲线起点的右侧上方，完全避开曲线)\n",
    "    # 选择x轴较早但y值仍很低的点\n",
    "    slow_begin_idx = 10  # x[10]大约在0.5，y值非常低\n",
    "    ax.annotate('Slow beginning', xy=(x[slow_begin_idx], y[slow_begin_idx]), \n",
    "                xytext=(x[slow_begin_idx]+3, y[slow_begin_idx]+20),  # 大幅向右上偏移\n",
    "                arrowprops=dict(arrowstyle='->', color='red', lw=1.5),\n",
    "                fontsize=10, color='red', fontweight='bold')\n",
    "\n",
    "    # 2. Steep acceleration (中间陡峭部分，x接近10)\n",
    "    steep_idx = len(x) // 2  # 大约在x=10的位置\n",
    "    ax.annotate('Steep acceleration', xy=(x[steep_idx], y[steep_idx]), \n",
    "                xytext=(x[steep_idx]-4, y[steep_idx]+20),  # 向左上偏移更多\n",
    "                arrowprops=dict(arrowstyle='->', color='green', lw=1.5),\n",
    "                fontsize=10, color='green', fontweight='bold')\n",
    "\n",
    "    # 3. Plateau (右上部分，x接近最大值)\n",
    "    plateau_idx = -40  # 接近末尾但不是最末端\n",
    "    ax.annotate('Plateau', xy=(x[plateau_idx], y[plateau_idx]), \n",
    "                xytext=(x[plateau_idx]-4, y[plateau_idx]-15),  # 向左下偏移\n",
    "                arrowprops=dict(arrowstyle='->', color='orange', lw=1.5),\n",
    "                fontsize=10, color='orange', fontweight='bold')\n",
    "\n",
    "    # 4. \"you did it!\" (接近最大值的地方，y接近100%)\n",
    "    success_idx = -20  # 不在最末端，避免与Plateau重叠\n",
    "    ax.annotate('you did it!', xy=(x[success_idx], y[success_idx]), \n",
    "                xytext=(x[success_idx]+2, y[success_idx]-20),  # 向右下偏移\n",
    "                bbox=dict(boxstyle=\"round,pad=0.3\", facecolor=\"lightgreen\", alpha=0.8),\n",
    "                arrowprops=dict(arrowstyle='->', color='darkgreen', lw=1.5),\n",
    "                fontsize=10, color='darkgreen', fontweight='bold')\n",
    "\n",
    "    # 调整布局以避免标签重叠\n",
    "    plt.tight_layout()\n",
    "    \n",
    "    # 显示图形\n",
    "    plt.show()\n",
    "\n",
    "# 执行绘图\n",
    "plot_learning_curve()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6636f291-9488-4444-bef5-74cd40d5f4d2",
   "metadata": {},
   "source": [
    "## 我的思考\n",
    "\n",
    "- 通义千问的编程能力有很大提升，下次作业换Claude来对比一下（如果还能用AI的话\n",
    "- AI编码的时候真的很热衷于给一大堆注释\n",
    "- 我没装Anaconda Navigator，我还是习惯拿Pycharms配环境，能避免很大麻烦"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
