目录文档-技术白皮书45-EFT.WP.Data.Pipeline v1.0

第7章 转换与预处理


I. 章节目的与范围

的规范:算子类型与参数、输入/输出 Σ_in/Σ_out 契约、幂等与可重放、缺失处理与标准化、时间/频率处理与重采样、特征构建对齐、异常处置与审计导出;确保与数据契约、模型卡特征空间、计量章与引用锚点一致。转换(transform)与预处理(preprocess)固化流水线

II. 术语与依赖


III. 字段与结构(规范性)

stage:

name: "<normalize|standardize|resample|impute|encode|tokenize|stft|specaugment|feature_map|aggregate|pca|custom>"

type: "transform.<op>|preprocess.<op>"

impl: "I16-3.<impl_id>"

inputs: ["<Σ_in>"]

outputs: ["<Σ_out>"]

params:

method: "<zscore|minmax|robust|unit-norm|...>"

stats_from: "train-only|all" # 统计量来源

window: "<samples|ms>?"

stride: "<samples|ms>?"

f_samp: "<Hz>?" # 重采样目标频率

anti_alias: {enabled:true, cutoff:"<Hz>", order:5}?

encode: {vocab_ref:"<path>", unk:"<token>", pad:"<token>"}?

impute: {strategy:"mean|median|knn|model", value: null}?

pca: {n_components:"<int|ratio>", whiten:false}?

idempotent: true

retries: {max: 2, backoff: "expo"}

timeout_s: 1800

on_fail: "quarantine|skip|block"

schema_ref: "<contracts/after_transform@vX.Y>" # 与输出契约绑定

feature_space:

type: "<dense|sparse|sequence|image|audio_spec|tabular|embedding>"

shape: "<(…)>"

dtype: "<float32|int32|...>"

normalization: "<zscore|minmax|robust|unit-norm|none>"


IV. 常见算子与口径

  1. 标准化/归一化(normalize|standardize)
    • zscore:( x - μ ) / σ;μ/σ 仅由训练集计算(stats_from:"train-only")并固化到锁定文件。
    • minmax/robust/unit-norm:显式区间与范数;对异常值采用截断或稳健统计并记录策略。
  2. 缺失值处理(impute)
    均值/中位数/KNN/模型推断;需记录对不确定度的影响并在相关章合成。
  3. 时间/频率处理与重采样(resample|stft|specaugment)
    声明 f_samp、抗混叠滤波(anti_alias)、插值方法;STFT 的 window/stride 与窗型(如 hann)必须给出。
  4. 编码/分词(encode|tokenize)
    vocab_ref、unk/pad、最大长度、截断/滑窗规则;分词/子词版本与哈希入库。
  5. 特征构建与降维(feature_map|aggregate|pca)
    特征函数/核与超参;PCA 需保存载荷矩阵与解释方差比;聚合对齐时间窗并声明缺失策略。
  6. 自定义算子(custom)
    提供容器/脚本引用与参数哈希;输入/输出契约显式化,失败回滚策略必须声明。

V. 幂等、可重放与异常处置


VI. 与特征空间/任务 I-O 的对齐


VII. 计量与单位(SI)

  1. 重采样频率 f_samp(Hz)、窗口/步长(ms 或样本)、时延 T_inf(ms)、吞吐 QPS(1/s)等一律使用 SI,配 metrology:{units:"SI", check_dim:true}。
  2. 若转换涉及路径量(如 T_arr),需登记:delta_form、path="gamma(ell)"、measure="d ell",并采用等价式之一:
    • T_arr = ( 1 / c_ref ) * ( ∫ n_eff d ell )
    • T_arr = ( ∫ ( n_eff / c_ref ) d ell );并通过 check_dim 校核。

VIII. 机器可读片段(可直接嵌入)

layers:

- name: "transform"

stages:

- name: "standardize.rgb"

type: "transform.normalize"

impl: "I16-3.standardize"

inputs: ["raw_image"]

outputs: ["img_std"]

params: {method:"zscore", stats_from:"train-only"}

idempotent: true

schema_ref: "contracts/img_std@v1.0"

feature_space: {type:"image", shape:"(H,W,3)", dtype:"float32", normalization:"zscore"}

- name: "resample.audio"

type: "transform.resample"

impl: "I16-3.resample"

inputs: ["waveform_48k"]

outputs: ["waveform_16k"]

params:

f_samp: 16000

anti_alias: {enabled:true, cutoff: 7600, order: 5}

idempotent: true

schema_ref: "contracts/waveform_16k@v1.0"

- name: "stft.spec"

type: "transform.stft"

impl: "I16-3.stft"

inputs: ["waveform_16k"]

outputs: ["spec"]

params: {window:512, stride:160, window_fn:"hann"}

feature_space: {type:"audio_spec", shape:"(F,T)", dtype:"float32", normalization:"zscore"}

idempotent: true


IX. Lint 规则(节选,规范性)

lint_rules:

- id: TF.IDEMPOTENT_REQUIRED

when: "$.layers[*].stages[?(@.type^='transform.')]"

assert: "idempotent == true"

level: error

- id: TF.STATS_FROM_TRAIN_ONLY

when: "$.layers[*].stages[?(@.params.stats_from)]"

assert: "value == 'train-only'"

level: error

- id: TF.FS_DECLARED

when: "$.layers[*].stages[*].feature_space"

assert: "has_keys(type,shape,dtype,normalization)"

level: error

- id: TF.RESAMPLE_SI

when: "$.layers[*].stages[?(@.type=='transform.resample')]"

assert: "is_number($.params.f_samp) and $.params.f_samp > 0"

level: error

- id: TF.UNITS_CHECKDIM

when: "$.pipeline.metrology"

assert: "units == 'SI' and check_dim == true"

level: error

- id: TF.PATH_TARR_FIELDS

when: "$.layers[*].stages[*].params[?(@.delta_form)]"

assert: "has_keys(delta_form) and has_keys(path) and has_keys(measure)"

level: error


X. 导出清单与审计

export_manifest:

version: "v1.0"

artifacts:

- {path:"transform/config.lock.yaml", sha256:"..."}

- {path:"transform/logs/step-*.jsonl", sha256:"..."}

- {path:"features/spec.yaml", sha256:"..."}

references:

- "EFT.WP.Core.DataSpec v1.0:EXPORT"

- "EFT.WP.Core.Metrology v1.0:check_dim"

- "EFT.WP.Data.ModelCards v1.0:Ch.9"


XI. 本章合规自检


版权与许可(CC BY 4.0)

版权声明:除另有说明外,《能量丝理论》(含文本、图表、插图、符号与公式)的著作权由作者(“屠广林”先生)享有。
许可方式:本作品采用 Creative Commons 署名 4.0 国际许可协议(CC BY 4.0)进行许可;在注明作者与来源的前提下,允许为商业或非商业目的进行复制、转载、节选、改编与再分发。
署名格式(建议):作者:“屠广林”;作品:《能量丝理论》;来源:energyfilament.org;许可证:CC BY 4.0。

首次发布: 2025-11-11|当前版本:v5.1
协议链接:https://creativecommons.org/licenses/by/4.0/