完整的 API 文档和代码示例
nct_manager.py主控制器,管理 NCT 的完整处理流程
__init__(config: NCTConfig)→ None初始化 NCT 管理器
process_cycle(sensory_data: dict)→ NCTState执行一个完整的处理周期
get_state()→ NCTState获取当前状态
nct_core.py配置类,定义所有超参数和架构设置
n_heads: int= 8注意力头数(工作空间容量)
n_layers: int= 6Transformer 层数(皮层深度)
d_model: int= 768模型维度(神经元数量)
n_candidates: int= 4多候选表征数量
gamma_freq: float= 40.0γ同步频率 (Hz)
nct_workspace.py注意力工作空间,实现全局广播和多候选竞争
forward(x: Tensor)→ Tensor, Tensor前向传播,返回输出和注意力权重
compute_salience(candidates: List[Tensor])→ List[float]计算每个候选的显著性
nct_metrics.pyΦ值计算器,度量整合信息
compute_phi(attention_maps: Tensor)→ float从注意力图计算Φ值
find_min_partition(mi_matrix: Tensor)→ tuple寻找最小信息分割
nct_hybrid_learning.pyTransformer-STDP 混合学习机制
apply_stdp(pre_spike: Tensor, post_spike: Tensor)→ Tensor应用 STDP 规则更新权重
neuromodulate(delta_w: Tensor, modulators: dict)→ Tensor神经调质门控
nct_predictive_coding.py预测编码模块,实现自由能最小化
predict(latent: Tensor)→ Tensor从隐变量生成预测
compute_free_energy(prediction: Tensor, actual: Tensor)→ Tensor计算变分自由能
nct_cross_modal.py跨模态融合模块,使用 Cross-Attention
fuse(modal1: Tensor, modal2: Tensor)→ Tensor融合两个模态的特征
align(features: List[Tensor])→ Tensor语义对齐多模态特征
nct_gamma_sync.pyγ同步机制,模拟 40Hz 振荡
generate_phase(t: float)→ float生成γ相位信号
phase_lock(signals: List[Tensor])→ Tensor实现相位锁定
from nct_modules import NCTManager, NCTConfig
# 创建配置
config = NCTConfig(
n_heads=8,
n_layers=6,
d_model=768,
n_candidates=4,
)
# 创建管理器
manager = NCTManager(config)
# 运行处理周期
for step in range(100):
sensory_input = get_sensory_data()
state = manager.process_cycle(sensory_input)
# 查看意识指标
print(f"Step {step}:")
print(f" Φ值:{state.phi:.3f}")
print(f" 自由能:{state.free_energy:.3f}")
print(f" Winner: {state.winner_index}")