Daily Deploy Bot 2 недель назад
Родитель
Сommit
392667fa56

+ 98 - 0
courseware/course_day1.html

@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<html lang="zh-CN">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>1 - 感知机</title>
+    <style>
+        body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; line-height: 1.6; max-width: 800px; margin: 0 auto; padding: 20px; background: #1a1a2e; color: #eaeaea; }
+        h1 { color: #e94560; border-bottom: 2px solid #e94560; padding-bottom: 10px; }
+        h2 { color: #0f3460; background: #16213e; padding: 10px; border-left: 4px solid #e94560; margin-top: 30px; }
+        .module { background: #0f3460; padding: 15px; margin: 20px 0; border-radius: 5px; }
+        .module-title { color: #e94560; font-weight: bold; margin-bottom: 10px; }
+        code { background: #1a1a2e; padding: 2px 6px; border-radius: 3px; color: #f0f6f6; }
+        pre { background: #1a1a2e; padding: 15px; border-radius: 5px; overflow-x: auto; }
+        .symbol-map { background: #16213e; padding: 10px; margin: 5px 0; border-left: 3px solid #0f3460; }
+        .warning { background: #e94560; color: #fff; padding: 10px; border-radius: 5px; margin: 10px 0; }
+        .youtube { background: #ff0000; color: #fff; padding: 10px; border-radius: 5px; display: inline-block; margin: 10px 0; }
+    </style>
+    https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css
+</head>
+<body>
+    <h1>👾 Day 1: 感知机</h1>
+    
+    <div class="module">
+        <div class="module-title">1️⃣【技术债与演进动机】The Technical Debt & Evolution</div>
+        之前的算法无法处理线性不可分数据,导致泛化能力差。感知机通过引入决策边界,将分类问题转化为优化问题。
+    </div>
+
+    <div class="module">
+        <div class="module-title">2️⃣【直觉建立】Visual Intuition</div>
+        想象一条直线(或超平面)将两类点分开。权重向量 $w$ 决定直线的方向,偏置 $b$ 决定直线的位置。
+        <div class="youtube">🎬 B 站搜索:<code>感知机 直观解释</code></div>
+    </div>
+
+    <div class="module">
+        <div class="module-title">3️⃣【符号解码字典】The Symbol Decoder</div>
+        
+    <div class="symbol-map">
+        <strong>$w$</strong> → <code>self.weights</code> (权重向量,shape: [d])
+    </div>
+    <div class="symbol-map">
+        <strong>$b$</strong> → <code>self.bias</code> (偏置标量,shape: [])
+    </div>
+    <div class="symbol-map">
+        <strong>$x$</strong> → <code>input_tensor</code> (输入样本,shape: [d])
+    </div>
+    <div class="symbol-map">
+        <strong>$y$</strong> → <code>label</code> (标签,值域:{-1, +1})
+    </div>
+    <div class="symbol-map">
+        <strong>$\sign(\cdot)$</strong> → <code>np.sign()</code> (符号函数)
+    </div>
+    <div class="symbol-map">
+        <strong>$\xi$</strong> → <code>margin</code> (间隔,用于更新步长)
+    </div>
+
+    </div>
+
+    <div class="module">
+        <div class="module-title">4️⃣【核心推导】The Math</div>
+        
+### 感知机预测函数
+
+$$f(x) = w \cdot x + b$$
+
+其中 $\cdot$ 表示向量点积。
+
+### 损失函数( hinge loss 的简化形式)
+
+$$L(w, b) = -\sum_{x_i \in M} y_i (w \cdot x_i + b)$$
+
+$M$ 是误分类点集合。
+
+### 梯度下降更新规则
+
+$$w \leftarrow w + \eta \cdot y_i \cdot x_i$$
+
+$$b \leftarrow b + \eta \cdot y_i$$
+
+其中 $\eta$ 是学习率。
+
+    </div>
+
+    <div class="module">
+        <div class="module-title">5️⃣【工程优化点】The Optimization Bottleneck</div>
+        全量梯度下降需要遍历所有样本,复杂度 $O(N \cdot d)$。现代框架使用 mini-batch SGD 加速。
+    </div>
+
+    <div class="module">
+        <div class="module-title">6️⃣【今日靶机】The OJ Mission</div>
+        <div class="warning">🎯 任务:<code>cd exercises/ && python3 day1_task.py</code></div>
+        实现感知机的 forward 和 update 函数,在 XOR 数据集上验证无法收敛(线性不可分)。
+    </div>
+
+    <script src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script>
+    <script>renderMathInElement(document.body);</script>
+</body>
+</html>

+ 72 - 0
exercises/day1_task.py

@@ -0,0 +1,72 @@
+"""
+Day 1 - 感知机 练习
+
+任务:实现 感知机 的核心算法
+"""
+
+import numpy as np
+import matplotlib.pyplot as plt
+
+
+class 感知机:
+    """感知机 类"""
+    
+    def __init__(self, learning_rate: float = 0.01):
+        self.learning_rate = learning_rate
+        self.weights = None
+        self.bias = None
+    
+    def forward(self, X: np.ndarray) -> np.ndarray:
+        """前向传播
+        
+        Args:
+            X: 输入数据,shape: [n_samples, n_features]
+            
+        Returns:
+            预测结果,shape: [n_samples]
+        """
+        # TODO: 实现 f(x) = sign(w · x + b)
+        raise NotImplementedError
+    
+    def compute_loss(self, X: np.ndarray, y: np.ndarray) -> float:
+        """计算损失"""
+        # TODO: 实现损失函数
+        raise NotImplementedError
+    
+    def update(self, X_i: np.ndarray, y_i: int):
+        """更新参数
+        
+        Args:
+            X_i: 单个样本,shape: [n_features]
+            y_i: 标签,值域 (-1, 1)
+        """
+        # TODO: 实现梯度下降更新
+        raise NotImplementedError
+    
+    def fit(self, X: np.ndarray, y: np.ndarray, max_iter: int = 100):
+        """训练模型"""
+        # TODO: 实现训练循环
+        raise NotImplementedError
+
+
+def plot_concept():
+    """可视化概念"""
+    # 生成二维数据
+    np.random.seed(42)
+    X = np.random.randn(100, 2)
+    y = np.sign(X[:, 0] + X[:, 1] - 0.5) * 1
+    
+    # 绘制散点图
+    plt.figure(figsize=(8, 6))
+    scatter = plt.scatter(X[:, 0], X[:, 1], c=y, cmap="bwr", s=100, edgecolors="black")
+    plt.xlabel("x1")
+    plt.ylabel("x2")
+    plt.title("Day 1 - 感知机 可视化")
+    plt.colorbar(scatter)
+    plt.grid(True, alpha=0.3)
+    plt.savefig("./plots/day1_concept.png", dpi=150)
+    print(f"✅ 可视化已保存:plots/day1_concept.png")
+
+
+if __name__ == "__main__":
+    plot_concept()

+ 13 - 1
memory/2026-02-28.md

@@ -32,6 +32,18 @@
 - 原代码:`Path(__file__).parent.parent.parent` (少了 1 层)
 - 修正后:`Path(__file__).resolve().parent.parent.parent.parent` (正确指向 workspace 根目录)
 
+### 配置更新 ✅
+
+**11:31 AM**: 更新教材路径配置
+
+- **旧路径**: `/home/zhn/ai/textbook` (不存在)
+- **新路径**: `/mnt/ai/textbooks` (已确认存在)
+
+**可用教材**:
+1. **统计学习方法** (`lihang-code/`) - 含感知机、KNN、朴素贝叶斯、EM 算法、HMM 等章节
+2. **动手学深度学习** (`d2l-zh/`) - 含计算图、卷积神经网络、注意力机制等章节
+3. **RL 数学基础** (`Book-Mathematical-Foundation-of-Reinforcement-Learning/`) - 含 MDP、Bellman 方程、价值迭代等章节
+
 ---
 
-*米醋 ✨ - 自动批处理完成*
+*米醋 ✨ - 自动批处理完成 + 配置更新*

+ 16 - 16
skills/mathlab/config.yaml

@@ -1,32 +1,32 @@
 # MathLab 配置文件
 
 # 教材路径(支持 PDF 或 Markdown)
-textbook_path: "/home/zhn/ai/textbook"
+textbook_path: "/mnt/ai/textbooks"
 textbooks:
   - name: "统计学习方法"
-    path: "统计学习方法_李航.pdf"
+    path: "lihang-code"
     phase: 1
     topics:
-      - "感知机"
-      - "KNN"
-      - "朴素贝叶斯"
-      - "EM 算法"
-      - "HMM"
+      - "第 02 章 感知机"
+      - "第 03 章 k 近邻法"
+      - "第 04 章 朴素贝叶斯"
+      - "第 09 章 EM 算法及其推广"
+      - "第 10 章 隐马尔可夫模型"
   - name: "动手学深度学习"
-    path: "d2l-en.pdf"
+    path: "d2l-zh"
     phase: 2
     topics:
-      - "计算图"
-      - "自动微分"
-      - "张量运算"
-      - "反向传播"
+      - "chapter_deep-learning-computation"
+      - "chapter_convolutional-neural-networks"
+      - "chapter_attention-mechanisms"
   - name: "Reinforcement Learning 数学基础"
-    path: "rl-math.pdf"
+    path: "Book-Mathematical-Foundation-of-Reinforcement-Learning"
     phase: 3
     topics:
-      - "状态空间"
-      - "MDP"
-      - "动态规划"
+      - "3 - Chapter 1 Basic Concepts.pdf"
+      - "3 - Chapter 2 State Values and Bellman Equation.pdf"
+      - "3 - Chapter 3 Optimal State Values and Bellman Optimality Equation.pdf"
+      - "3 - Chapter 4 Value Iteration and Policy Iteration.pdf"
 
 # Git 仓库配置
 gogs_url: "https://gogs.example.com/user/mathlab.git"

+ 1 - 1
skills/mathlab/scripts/deploy_day.py

@@ -9,7 +9,7 @@ import sys
 from pathlib import Path
 import yaml
 
-PROJECT_ROOT = Path(__file__).parent.parent.parent
+PROJECT_ROOT = Path(__file__).resolve().parent.parent.parent.parent
 
 def load_config() -> dict:
     """加载配置"""

+ 34 - 0
tests/test_day1.py

@@ -0,0 +1,34 @@
+"""
+Day 1 - 感知机 测试用例
+"""
+
+import numpy as np
+import sys
+sys.path.append("../exercises")
+
+# TODO: 导入对应的类
+# from day1_task import *
+
+
+def test_forward_shape():
+    """测试前向传播输出形状"""
+    # TODO: 实现测试
+    assert True
+
+
+def test_loss_computation():
+    """测试损失计算"""
+    # TODO: 实现测试
+    assert True
+
+
+def test_update_rule():
+    """测试参数更新规则"""
+    # TODO: 实现测试
+    assert True
+
+
+def test_convergence():
+    """测试收敛性"""
+    # TODO: 实现测试
+    assert True