Forgetting Curve 模块
独立的 Ebbinghaus 遗忘曲线实现,为记忆系统提供标准化衰减计算。
功能特性
- - 多种衰减模型:Ebbinghaus 指数衰减、幂律衰减、自定义半衰期
- 间隔重复调度:基于记忆强度的下一次复习时间计算
- 可配置参数:半衰期、初始强度、衰减因子
- 跨平台兼容:独立模块,无外部依赖
核心算法
Ebbinghaus 指数衰减
CODEBLOCK0
其中:
- -
age_days: 距离最后一次复习的天数 - INLINECODE1 : 半衰期(默认 30 天)
间隔重复调度(SRS)
CODEBLOCK1
其中:
- -
base_interval: 基础间隔(如 1 天) - INLINECODE3 : 当前记忆强度(0.0-1.0)
- INLINECODE4 : 强度因子(默认 1.5)
使用方法
基本衰减计算
CODEBLOCK2
间隔重复调度
CODEBLOCK3
批量处理
CODEBLOCK4
配置参数
| 参数 | 类型 | 默认值 | 说明 |
|---|
| INLINECODE5 | float | 30.0 | 半衰期(天) |
| INLINECODE6 |
float | 1.0 | 初始记忆强度 |
|
minimum_strength | float | 0.1 | 最低强度阈值 |
|
base_interval | float | 1.0 | 基础复习间隔(天) |
|
strength_factor | float | 1.5 | 强度因子 |
|
easy_factor | float | 1.3 | 简单记忆因子 |
|
hard_factor | float | 0.8 | 困难记忆因子 |
与现有系统集成
1. Memory Sync Enhanced
CODEBLOCK5
2. CortexGraph 集成
CODEBLOCK6
扩展性
自定义衰减函数
CODEBLOCK7
多级记忆系统
CODEBLOCK8
性能基准
CODEBLOCK9
安装
作为独立模块
CODEBLOCK10
作为 OpenClaw 技能
CODEBLOCK11
开发指南
项目结构
CODEBLOCK12
运行测试
CODEBLOCK13
路线图
v0.1.0 (MVP)
- - [x] 基本 Ebbinghaus 衰减计算
- [x] 可配置半衰期
- [x] 强度衰减应用
v0.2.0
- - [ ] 间隔重复调度
- [ ] 多种衰减模型(幂律、指数混合)
- [ ] 批量处理优化
v0.3.0
- - [ ] 记忆分类(STM/LTM)
- [ ] 自适应半衰期(基于使用频率)
- [ ] 可视化工具
v1.0.0
- - [ ] 完整 SRS 算法
- [ ] 与 Anki/Mnemosyne 兼容
- [ ] 跨语言绑定
参考
- - Hermann Ebbinghaus (1885) - 遗忘曲线
- Piotr Wozniak (1987) - SuperMemo 算法
- Spaced Repetition Systems - 现代间隔重复理论
版本: 0.1.0
独立的 Ebbinghaus 遗忘曲线模块
遗忘曲线模块
独立的艾宾浩斯遗忘曲线实现,为记忆系统提供标准化衰减计算。
功能特性
- - 多种衰减模型:艾宾浩斯指数衰减、幂律衰减、自定义半衰期
- 间隔重复调度:基于记忆强度的下次复习时间计算
- 可配置参数:半衰期、初始强度、衰减因子
- 跨平台兼容:独立模块,无外部依赖
核心算法
艾宾浩斯指数衰减
decay = 2^(-agedays / halflife_days)
其中:
- - agedays:距离上次复习的天数
- halflife_days:半衰期(默认30天)
间隔重复调度(SRS)
nextreviewdays = base_interval * (strength ^ factor)
其中:
- - base_interval:基础间隔(如1天)
- strength:当前记忆强度(0.0-1.0)
- factor:强度因子(默认1.5)
使用方法
基本衰减计算
python
from forgetting_curve import ForgettingCurve
创建衰减器(默认半衰期30天)
curve = ForgettingCurve(half
lifedays=30.0)
计算衰减因子
age_days = 7 # 7天前记忆
decay = curve.calculate
decay(agedays) # 返回0.82
将衰减应用于记忆强度
original_strength = 0.9
decayed
strength = curve.applydecay(original
strength, agedays) # 0.74
间隔重复调度
python
from forgetting_curve import SpacedRepetitionScheduler
scheduler = SpacedRepetitionScheduler()
计算下次复习时间
current_strength = 0.6
next
reviewdays = scheduler.next
reviewinterval(current_strength) # 3.1天
更新记忆强度(复习后)
new
strength = scheduler.updatestrength(current_strength, success=True) # 0.75
批量处理
python
批量计算衰减
import pandas as pd
from forgetting
curve import batchdecay
memories = [
{id: mem1, strength: 0.9, age_days: 3},
{id: mem2, strength: 0.7, age_days: 15},
{id: mem3, strength: 0.5, age_days: 60}
]
decayed = batchdecay(memories, halflife_days=30)
返回包含衰减后强度的列表
配置参数
| 参数 | 类型 | 默认值 | 说明 |
|---|
| halflifedays | float | 30.0 | 半衰期(天) |
| initial_strength |
float | 1.0 | 初始记忆强度 |
| minimum_strength | float | 0.1 | 最低强度阈值 |
| base_interval | float | 1.0 | 基础复习间隔(天) |
| strength_factor | float | 1.5 | 强度因子 |
| easy_factor | float | 1.3 | 简单记忆因子 |
| hard_factor | float | 0.8 | 困难记忆因子 |
与现有系统集成
1. Memory Sync Enhanced
python
在cooccurrencetracker.py中替换硬编码衰减
旧代码:
decay = math.pow(2, -age_days / 30.0)
新代码:
from forgetting_curve import ForgettingCurve
curve = ForgettingCurve(half
lifedays=30.0)
decay = curve.calculate
decay(agedays)
2. CortexGraph集成
python
在检索时应用遗忘曲线过滤
from forgetting_curve import ForgettingCurve
def retrievememories(query, topk=10):
# ... 语义搜索 ...
for mem in results:
agedays = (datetime.now() - mem.lastused).days
decay = curve.calculatedecay(agedays)
mem.score *= decay
# ... 返回结果 ...
扩展性
自定义衰减函数
python
from forgetting_curve import ForgettingCurve
自定义衰减函数
def custom
decay(agedays, strength):
return strength * math.exp(-age_days / 45.0)
curve = ForgettingCurve(decayfunction=customdecay)
多级记忆系统
python
不同记忆类型使用不同半衰期
short
term = ForgettingCurve(halflife_days=3.0) # 短期记忆
long
term = ForgettingCurve(halflife_days=90.0) # 长期记忆
procedural = ForgettingCurve(half
lifedays=7.0) # 程序性记忆
性能基准
1000次衰减计算:0.8ms
10000次批量衰减:5.2ms
内存占用:< 1MB
安装
作为独立模块
bash
从当前目录安装
pip install -e .
或直接复制文件
cp forgetting_curve.py /your/project/
作为OpenClaw技能
bash
通过ClawHub发布后
clawhub install forgetting-curve
开发指南
项目结构
forgetting-curve/
├── forgetting_curve.py # 核心模块
├── test_decay.py # 单元测试
├── examples/ # 使用示例
├── config/ # 配置文件
└── SKILL.md # 本文档
运行测试
bash
python test_decay.py
路线图
v0.1.0(MVP)
- - [x] 基本艾宾浩斯衰减计算
- [x] 可配置半衰期
- [x] 强度衰减应用
v0.2.0
- - [ ] 间隔重复调度
- [ ] 多种衰减模型(幂律、指数混合)
- [ ] 批量处理优化
v0.3.0
- - [ ] 记忆分类(STM/LTM)
- [ ] 自适应半衰期(基于使用频率)
- [ ] 可视化工具
v1.0.0
- - [ ] 完整SRS算法
- [ ] 与Anki/Mnemosyne兼容
- [ ] 跨语言绑定
参考
- - Hermann Ebbinghaus(1885)- 遗忘曲线
- Piotr Wozniak(1987)- SuperMemo算法
- 间隔重复系统 - 现代间隔重复理论
版本:0.1.0
独立的艾宾浩斯遗忘曲线模块