dea-toolkit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. dea_toolkit-0.1.0/LICENSE +21 -0
  2. dea_toolkit-0.1.0/MANIFEST.in +5 -0
  3. dea_toolkit-0.1.0/PKG-INFO +533 -0
  4. dea_toolkit-0.1.0/README.md +501 -0
  5. dea_toolkit-0.1.0/additive_models.py +440 -0
  6. dea_toolkit-0.1.0/bootstrap_dea.py +449 -0
  7. dea_toolkit-0.1.0/by_production.py +326 -0
  8. dea_toolkit-0.1.0/context_dependent_dea.py +423 -0
  9. dea_toolkit-0.1.0/cross_efficiency.py +411 -0
  10. dea_toolkit-0.1.0/dea_core.py +949 -0
  11. dea_toolkit-0.1.0/dea_tobit.py +344 -0
  12. dea_toolkit-0.1.0/dea_toolkit.egg-info/PKG-INFO +533 -0
  13. dea_toolkit-0.1.0/dea_toolkit.egg-info/SOURCES.txt +32 -0
  14. dea_toolkit-0.1.0/dea_toolkit.egg-info/dependency_links.txt +1 -0
  15. dea_toolkit-0.1.0/dea_toolkit.egg-info/entry_points.txt +22 -0
  16. dea_toolkit-0.1.0/dea_toolkit.egg-info/requires.txt +9 -0
  17. dea_toolkit-0.1.0/dea_toolkit.egg-info/top_level.txt +22 -0
  18. dea_toolkit-0.1.0/directional_distance.py +379 -0
  19. dea_toolkit-0.1.0/dynamic_sbm.py +506 -0
  20. dea_toolkit-0.1.0/interval_dea.py +340 -0
  21. dea_toolkit-0.1.0/inverse_dea.py +282 -0
  22. dea_toolkit-0.1.0/malmquist_index.py +596 -0
  23. dea_toolkit-0.1.0/meta_frontier.py +314 -0
  24. dea_toolkit-0.1.0/pyproject.toml +71 -0
  25. dea_toolkit-0.1.0/radial_models.py +503 -0
  26. dea_toolkit-0.1.0/setup.cfg +4 -0
  27. dea_toolkit-0.1.0/stochastic_dea.py +332 -0
  28. dea_toolkit-0.1.0/super_sbm.py +590 -0
  29. dea_toolkit-0.1.0/three_stage_dea.py +376 -0
  30. dea_toolkit-0.1.0/two_stage_dea.py +290 -0
  31. dea_toolkit-0.1.0/undesirable_sbm.py +368 -0
  32. dea_toolkit-0.1.0/weak_disposability_ddf.py +326 -0
  33. dea_toolkit-0.1.0/weight_restricted_dea.py +313 -0
  34. dea_toolkit-0.1.0/window_analysis.py +330 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ethan Wang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,5 @@
1
+ prune tests
2
+ exclude sample_data.csv
3
+ prune .idea
4
+ prune .ruff_cache
5
+ global-exclude __pycache__ *.py[cod]
@@ -0,0 +1,533 @@
1
+ Metadata-Version: 2.4
2
+ Name: dea-toolkit
3
+ Version: 0.1.0
4
+ Summary: Data envelopment analysis (DEA) toolkit with 21 command-line models
5
+ Author-email: Ethan Wang <15940618608@163.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/factorbyte/dea-toolkit
8
+ Project-URL: Repository, https://github.com/factorbyte/dea-toolkit
9
+ Project-URL: Issues, https://github.com/factorbyte/dea-toolkit/issues
10
+ Keywords: DEA,efficiency,SBM,Malmquist,operations research
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Science/Research
13
+ Classifier: Operating System :: OS Independent
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
20
+ Requires-Python: >=3.11
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: numpy<2.8,>=2.0
24
+ Requires-Dist: scipy<2,>=1.16
25
+ Requires-Dist: openpyxl<4,>=3.1
26
+ Provides-Extra: dev
27
+ Requires-Dist: build>=1.5; extra == "dev"
28
+ Requires-Dist: twine>=6.1; extra == "dev"
29
+ Requires-Dist: pytest>=8; extra == "dev"
30
+ Requires-Dist: ruff>=0.6; extra == "dev"
31
+ Dynamic: license-file
32
+
33
+ # dea-toolkit
34
+
35
+ 数据包络分析(DEA)脚本集。采用“共享核心 + 分族脚本”的组织方式:`dea_core.py` 提供数据读取、校验、报表与线性规划公共工具,每个模型族一个可独立运行的脚本。
36
+
37
+ ## 当前功能
38
+
39
+ ### `super_sbm.py`:标准 SBM、超效率 SBM 与加权 SBM
40
+
41
+ 实现标准 SBM(Tone 2001)与超效率 SBM(Tone 2002)的两阶段计算:
42
+
43
+ - 规模报酬:`crs`(不变)/ `vrs`(可变)
44
+ - 评分口径:`super`(有效单元得分可超过 1)/ `standard`(得分上限为 1)
45
+ - 加权 SBM:通过 `INPUT_WEIGHTS` / `OUTPUT_WEIGHTS` 指定指标权重,按组归一化到和为 1;不指定即等权
46
+ - 数据:CSV / Excel(.xlsx / .xlsm),首行为表头
47
+ - 变量:投入、期望产出、非期望产出(按投入方向处理)
48
+ - 面板数据:DMU 可用多列自动拼接,如“城市代码-年份”
49
+ - 输出:控制台报表,可选导出 CSV(得分、排名、投入冗余、期望产出不足、非期望产出冗余)
50
+
51
+ 非导向标准 SBM 的得分公式与增强 Russell 测度(ERM)相同,因此 `--score-mode standard` 得到的就是 ERM 得分,未另建重复脚本。
52
+
53
+ ### `radial_models.py`:CCR / BCC 径向模型
54
+
55
+ - 规模报酬:`crs`(CCR)/ `vrs`(BCC)
56
+ - 导向:`input`(投入导向)/ `output`(产出导向)
57
+ - 评分口径:`super` / `standard`
58
+ - 得分统一为“越大越好”;产出导向原始值为 φ,得分为 1/φ
59
+ - VRS 径向超效率可能不可行:超效率列留空、最终得分按 1.0 处理并给出提示
60
+ - 非期望产出按投入方向并入投入块
61
+ - 数据读取、报表与 CSV 导出能力与 SBM 脚本一致
62
+
63
+ ### `additive_models.py`:Additive / RAM
64
+
65
+ - `additive`:加性模型,报告松弛和目标值(0 为有效),排名按目标值升序;不提供 0-1 得分
66
+ - `ram`:范围调整测度,以指标极差的倒数为权重,给出 0-1 的 RAM 得分与加权松弛和
67
+ - RAM 要求 `vrs`;Additive 支持 `crs` / `vrs`
68
+ - 非期望产出按投入方向并入投入块;零极差指标会自动从 RAM 权重中剔除并提示
69
+
70
+ ### `directional_distance.py`:方向距离函数(DDF)
71
+
72
+ - 方向模式:`proportional`(g_x = x_o, g_y = y_o,尺度不变)/ `unit`(各指标方向为 1)
73
+ - 规模报酬:`crs` / `vrs`
74
+ - 报告 β(0 为有效,越大越无效)与投影松弛,排名按 β 升序;DDF 不提供 0-1 得分
75
+ - 非期望产出按投入方向并入投入块,β 同时缩减非期望产出
76
+
77
+ ### `cross_efficiency.py`:交叉效率
78
+
79
+ - CCR 乘数型自评效率 + Doyle-Green 二级目标(`aggressive` 进取型 / `benevolent` 仁慈型)
80
+ - 输出完整的交叉效率矩阵、每列均值(含自评)与排名
81
+ - 可分别导出交叉效率均值 CSV 与矩阵长表 CSV
82
+
83
+ ### `context_dependent_dea.py`:Context-dependent DEA
84
+
85
+ - 输出导向径向 DEA 逐层剔除有效单元,得到第 1 层、第 2 层……
86
+ - 吸引力 A:相对更差层(l+d);进步 P:相对更好层(l-d);`COMPARISON_DISTANCE` 可设层间距
87
+ - 规模报酬:`crs`(Seiford-Zhu 原始设定)/ `vrs`
88
+ - 边界层或不可行时 A/P 留空
89
+
90
+ ### `bootstrap_dea.py`:Simar-Wilson Bootstrap DEA
91
+
92
+ - 输入导向径向 DEA 的同质平滑 bootstrap(反射、方差校正、伪数据重估)
93
+ - 输出原始得分、bootstrap 偏差、偏差校正得分、标准误与百分位置信区间
94
+ - `BOOTSTRAP_REPETITIONS`、`CONFIDENCE_LEVEL`、`RANDOM_SEED`、`SMOOTHING_BANDWIDTH` 可配置
95
+ - 默认带宽使用 Silverman 经验规则;不处理环境变量或异质前沿
96
+
97
+ ### `undesirable_sbm.py`:严格非期望产出 SBM
98
+
99
+ - Tone 2003 非导向 SBM:非期望产出作为“越少越好”的产出进入分母
100
+ - 与 `super_sbm.py` 把非期望产出并入投入块的简化处理不同
101
+ - 支持 `crs` / `vrs`;输出投入冗余、期望产出不足、非期望产出冗余
102
+
103
+ ### `weak_disposability_ddf.py`:弱可处置性 DDF
104
+
105
+ - 方向 g=(x, y, b):同时收缩投入、扩张期望产出、缩减非期望产出
106
+ - 非期望产出使用等式弱可处置约束,不能自由处置减少
107
+ - 支持 `crs` / `vrs`;报告 β 与投影松弛
108
+
109
+ ### `meta_frontier.py`:共同前沿
110
+
111
+ - 分组前沿与共同前沿的投入导向径向效率
112
+ - 技术落差比 `TGR = 共同前沿效率 / 组前沿效率`
113
+ - 需要分组列(如 `区域`);支持 `crs` / `vrs`
114
+
115
+ ### `malmquist_index.py`:Malmquist / Malmquist-Luenberger
116
+
117
+ - 平衡面板的相邻期或全局前沿生产率指数;要求期别列与实体列
118
+ - `malmquist`:输出导向径向距离函数,不纳入非期望产出
119
+ - `ml`:方向 g=(y, -b) 的 DDF,同时扩张期望产出、缩减非期望产出
120
+ - `FRONTIER_MODE`:`adjacent`(相邻期)或 `global`(全局前沿)
121
+ - 输出 M/ML、EC、TC;混合期 LP 不可行时留空
122
+
123
+ ### `window_analysis.py`:窗口分析
124
+
125
+ - 滑动宽度为 `WINDOW_WIDTH` 的期别窗口,在每个窗口内做投入导向径向 DEA
126
+ - 同一实体-期别观测跨窗口取平均,输出平均得分、参与窗口数与排名
127
+ - 支持 `crs` / `vrs`;非期望产出按投入方向并入投入块
128
+
129
+ ### `dynamic_sbm.py`:动态 SBM(Tone–Tsutsui 2010)
130
+
131
+ - 跨期非导向 SBM,结转变量按“好结转(越多越好)/坏结转(越少越好)”处理
132
+ - 连续性与跨期松弛在同一个 LP 中求解,输出综合得分与各期得分
133
+ - 要求平衡面板,结转变量须为正数;当前期非期望产出按投入方向处理
134
+
135
+ ### `two_stage_dea.py`:串行两阶段网络 DEA
136
+
137
+ - Kao–Hwang 合作式乘数模型:阶段 1 投入 → 中间产品 → 阶段 2 最终产出
138
+ - 整体效率 = 阶段 1 效率 × 阶段 2 效率;整体效率固定后最大化阶段 1 得到分解
139
+ - 中间产品使用共同乘数连接两个阶段
140
+ - 当前为 CRS 串行模型,不包含共享投入、阶段 2 额外投入与非期望产出
141
+
142
+ ### `three_stage_dea.py`:三阶段 DEA(DEA + SFA + DEA)
143
+
144
+ - 阶段 1:投入导向径向 DEA,提取投入总松弛
145
+ - 阶段 2:对每个投入松弛做半正态 SFA,分解环境效应、统计噪声与管理无效率
146
+ - 阶段 3:将投入向上调整到最差环境/运气后重跑 DEA,得到管理效率
147
+ - 需要环境变量列;支持 `crs` / `vrs`
148
+
149
+ ### `inverse_dea.py`:Inverse DEA
150
+
151
+ - 给定目标产出倍数 f,求每个 DMU 的最小比例投入 α
152
+ - 所需投入 = α × 原投入;当前为比例投入反推,不是逐项非比例模型
153
+ - 支持 `crs` / `vrs`;不处理非期望产出
154
+
155
+ ### `dea_tobit.py`:DEA-Tobit
156
+
157
+ - 第一阶段投入导向径向 DEA;第二阶段以效率为因变量、环境变量为自变量做上限 1 的 Tobit MLE
158
+ - 输出系数、数值 Hessian 标准误、z 值与 p 值
159
+ - 需要环境变量列;支持 `crs` / `vrs`
160
+
161
+ ### `weight_restricted_dea.py`:权重约束 CCR
162
+
163
+ - 以第一项指标为基准设定投入/产出权重比例上下界(Assurance Region)
164
+ - 当前为 CRS 乘数模型;不处理非期望产出
165
+
166
+ ### `by_production.py`:By-production(简化)
167
+
168
+ - T1:全部投入 → 期望产出的运营效率
169
+ - T2(简化):污染性投入不扩张约束下最小化非期望产出比率
170
+ - 综合效率 = (运营效率 + 环境效率) / 2;污染性投入由配置区指定
171
+
172
+ ### `interval_dea.py`:区间 / 模糊 DEA
173
+
174
+ - 按相对不确定度构造投入产出区间:`x ∈ [x(1−p), x(1+p)]`,产出同理
175
+ - 下界:自身取最差端点、参考集取最好端点;上界相反;中心为原始数据径向效率
176
+ - `MODE="fuzzy"` 使用三角模糊数的 α=0 支撑区间与 α=1 中心
177
+ - VRS 端点 LP 可能不可行(最好情形产出超出参考集凸包),此时区间留空并在备注提示
178
+ - 排名按区间中点;非期望产出按投入方向并入投入块
179
+
180
+ ### `stochastic_dea.py`:随机 DEA(蒙特卡洛)
181
+
182
+ - 每次情景给所有投入/产出乘以独立乘性因子,因子服从中位数 1 的对数正态分布
183
+ - 重复模拟后汇总均值、标准差、P5/P50/P95 与有效概率(θ ≥ 1 − 容差的情景占比)
184
+ - `SIGMA=0` 时退化为确定性径向效率;固定 `RANDOM_SEED` 可复现
185
+ - 排名按均值效率;非期望产出按投入方向并入投入块并参与扰动
186
+
187
+ ## 项目结构
188
+
189
+ ```
190
+ dea-toolkit/
191
+ ├── dea_core.py # 公共核心:数据读取/校验、报表/CSV、线性规划、命令行数据参数
192
+ ├── super_sbm.py # 标准 / 超效率 / 加权 SBM(标准模式即 ERM)
193
+ ├── radial_models.py # CCR / BCC 径向模型
194
+ ├── additive_models.py # Additive / RAM
195
+ ├── directional_distance.py # 方向距离函数(DDF)
196
+ ├── cross_efficiency.py # 交叉效率(Doyle-Green 二级目标)
197
+ ├── context_dependent_dea.py # Context-dependent DEA(分层、吸引力/进步)
198
+ ├── bootstrap_dea.py # Simar-Wilson Bootstrap DEA
199
+ ├── undesirable_sbm.py # 严格非期望产出 SBM(Tone 2003)
200
+ ├── weak_disposability_ddf.py # 弱可处置性 DDF
201
+ ├── meta_frontier.py # 共同前沿与 TGR
202
+ ├── malmquist_index.py # Malmquist / Malmquist-Luenberger
203
+ ├── window_analysis.py # 窗口分析
204
+ ├── dynamic_sbm.py # Tone-Tsutsui 动态 SBM
205
+ ├── two_stage_dea.py # 串行两阶段网络 DEA
206
+ ├── three_stage_dea.py # 三阶段 DEA(DEA + SFA 调整)
207
+ ├── inverse_dea.py # Inverse DEA
208
+ ├── dea_tobit.py # DEA-Tobit
209
+ ├── weight_restricted_dea.py # 权重约束 CCR
210
+ ├── by_production.py # By-production(简化)
211
+ ├── interval_dea.py # 区间 / 模糊 DEA
212
+ ├── stochastic_dea.py # 随机 DEA(蒙特卡洛)
213
+ ├── sample_data.csv # 4 城市 × 3 年面板示例(仓库示例,不打入 PyPI 包)
214
+ ├── pyproject.toml # PyPI 打包与 dea-* 命令行入口
215
+ ├── LICENSE # MIT
216
+ ├── requirements.txt
217
+ └── tests/
218
+ ├── generate_goldens.py # 重新生成 super_sbm 输出基线(手动运行)
219
+ ├── golden/ # golden 基线输出
220
+ ├── test_core.py
221
+ ├── test_super_sbm_compat.py
222
+ ├── test_radial_models.py
223
+ ├── test_weighted_sbm.py
224
+ ├── test_additive_models.py
225
+ ├── test_directional_distance.py
226
+ ├── test_cross_efficiency.py
227
+ ├── test_context_dependent_dea.py
228
+ ├── test_bootstrap_dea.py
229
+ ├── test_undesirable_sbm.py
230
+ ├── test_weak_disposability_ddf.py
231
+ ├── test_meta_frontier.py
232
+ ├── test_malmquist_index.py
233
+ ├── test_window_analysis.py
234
+ ├── test_dynamic_sbm.py
235
+ ├── test_two_stage_dea.py
236
+ ├── test_three_stage_dea.py
237
+ ├── test_inverse_dea.py
238
+ ├── test_dea_tobit.py
239
+ ├── test_weight_restricted_dea.py
240
+ ├── test_by_production.py
241
+ ├── test_interval_dea.py
242
+ └── test_stochastic_dea.py
243
+ ```
244
+
245
+ ## 安装
246
+
247
+ 要求 Python ≥ 3.11。
248
+
249
+ ### 从 PyPI 安装
250
+
251
+ ```bash
252
+ pip install dea-toolkit
253
+ ```
254
+
255
+ 每个模型对应一个 `dea-*` 命令,参数与原脚本一致;`--help` 查看完整选项:
256
+
257
+ ```text
258
+ dea-super-sbm super_sbm.py 标准 / 超效率 / 加权 SBM
259
+ dea-radial radial_models.py CCR / BCC 径向模型
260
+ dea-additive additive_models.py Additive / RAM
261
+ dea-ddf directional_distance.py 方向距离函数
262
+ dea-cross-efficiency cross_efficiency.py 交叉效率
263
+ dea-context-dependent context_dependent_dea.py Context-dependent DEA
264
+ dea-bootstrap bootstrap_dea.py Simar-Wilson Bootstrap
265
+ dea-undesirable-sbm undesirable_sbm.py 严格非期望产出 SBM
266
+ dea-weak-ddf weak_disposability_ddf.py 弱可处置性 DDF
267
+ dea-meta-frontier meta_frontier.py 共同前沿
268
+ dea-malmquist malmquist_index.py Malmquist / ML
269
+ dea-window window_analysis.py 窗口分析
270
+ dea-dynamic-sbm dynamic_sbm.py 动态 SBM
271
+ dea-two-stage two_stage_dea.py 串行两阶段网络 DEA
272
+ dea-three-stage three_stage_dea.py 三阶段 DEA
273
+ dea-inverse inverse_dea.py Inverse DEA
274
+ dea-tobit dea_tobit.py DEA-Tobit
275
+ dea-weight-restricted weight_restricted_dea.py 权重约束 CCR
276
+ dea-by-production by_production.py By-production
277
+ dea-interval interval_dea.py 区间 / 模糊 DEA
278
+ dea-stochastic stochastic_dea.py 随机 DEA
279
+ ```
280
+
281
+ 例如:
282
+
283
+ ```bash
284
+ dea-super-sbm --demo
285
+ dea-interval --demo --mode fuzzy --uncertainty 0.1
286
+ dea-super-sbm path/to/data.csv --dmu-columns 城市代码 年份 \
287
+ --input-columns 资本投入 劳动投入 --desirable-output-columns GDP 财政收入
288
+ ```
289
+
290
+ PyPI 的 wheel **不包含** `sample_data.csv`。安装包用户请先用 `--demo` 查看内置示例,
291
+ 或把数据文件路径作为第一个位置参数传入。仓库检出中仍保留该文件,可直接使用。
292
+
293
+ ### 从源码安装
294
+
295
+ ```bash
296
+ python -m pip install -r requirements.txt
297
+ # 或者安装为可编辑包,获得 dea-* 命令
298
+ python -m pip install -e .
299
+ ```
300
+
301
+ 依赖:numpy、scipy、openpyxl。
302
+
303
+ ## 使用
304
+
305
+ 1. 修改脚本【用户配置区】中的 `DATA_FILE`、`DMU_COLUMNS`、`INPUT_COLUMNS`、`DESIRABLE_OUTPUT_COLUMNS`、`UNDESIRABLE_OUTPUT_COLUMNS` 等,然后运行:
306
+
307
+ ```bash
308
+ python super_sbm.py
309
+ python radial_models.py
310
+ python additive_models.py
311
+ python directional_distance.py
312
+ python cross_efficiency.py
313
+ python context_dependent_dea.py
314
+ python bootstrap_dea.py
315
+ python undesirable_sbm.py
316
+ python weak_disposability_ddf.py
317
+ python meta_frontier.py
318
+ python malmquist_index.py
319
+ python window_analysis.py
320
+ python dynamic_sbm.py
321
+ python two_stage_dea.py
322
+ python three_stage_dea.py
323
+ python inverse_dea.py
324
+ python dea_tobit.py
325
+ python weight_restricted_dea.py
326
+ python by_production.py
327
+ python interval_dea.py
328
+ python stochastic_dea.py
329
+ ```
330
+
331
+ 径向模型另有 `ORIENTATION`(`input` / `output`)与 `RETURNS_TO_SCALE`(`crs` / `vrs`);SBM 另有 `INPUT_WEIGHTS` / `OUTPUT_WEIGHTS`;加性族另有 `MODEL`(`additive` / `ram`)与 `RETURNS_TO_SCALE`;DDF 另有 `DIRECTION_MODE`(`proportional` / `unit`)与 `RETURNS_TO_SCALE`;交叉效率另有 `SECONDARY_OBJECTIVE` 与 `MATRIX_FILE`;Context-dependent 另有 `COMPARISON_DISTANCE` 与 `RETURNS_TO_SCALE`;Bootstrap 另有 `BOOTSTRAP_REPETITIONS`、`CONFIDENCE_LEVEL`、`RANDOM_SEED`、`SMOOTHING_BANDWIDTH`;环境/面板脚本另有 `GROUP_COLUMN`、`PERIOD_COLUMN`、`ENTITY_COLUMNS`、`INDEX_TYPE`、`FRONTIER_MODE`、`WINDOW_WIDTH`、`GOOD_CARRY_OVER_COLUMNS`、`BAD_CARRY_OVER_COLUMNS`、`INTERMEDIATE_COLUMNS` 等。
332
+
333
+ 2. 运行内置示例:
334
+
335
+ ```bash
336
+ python super_sbm.py --demo
337
+ python radial_models.py --demo --orientation output --returns-to-scale vrs
338
+ python additive_models.py --demo --model ram
339
+ python directional_distance.py --demo --direction proportional
340
+ python cross_efficiency.py --demo --objective benevolent
341
+ python context_dependent_dea.py --demo --distance 2
342
+ python bootstrap_dea.py --demo --repetitions 50
343
+ python undesirable_sbm.py --demo
344
+ python weak_disposability_ddf.py --demo
345
+ python meta_frontier.py --demo
346
+ python malmquist_index.py --demo
347
+ python window_analysis.py --demo --window 2
348
+ python dynamic_sbm.py --demo
349
+ python two_stage_dea.py --demo
350
+ python three_stage_dea.py --demo
351
+ python inverse_dea.py --demo --factor 1.1
352
+ python dea_tobit.py --demo
353
+ python weight_restricted_dea.py --demo
354
+ python by_production.py --demo
355
+ python interval_dea.py --demo --uncertainty 0.05
356
+ python stochastic_dea.py --demo --sigma 0.1 --simulations 500
357
+ ```
358
+
359
+ 3. 命令行覆盖示例(完整参数见各脚本 `--help`):
360
+
361
+ ```bash
362
+ python super_sbm.py sample_data.csv \
363
+ --dmu-columns 城市代码 年份 \
364
+ --input-columns 资本投入 劳动投入 \
365
+ --desirable-output-columns GDP 财政收入 \
366
+ --undesirable-output-columns 工业废水排放量 \
367
+ --returns-to-scale crs \
368
+ --score-mode super \
369
+ --result-file dea_results.csv
370
+ ```
371
+
372
+ ```bash
373
+ python radial_models.py sample_data.csv \
374
+ --dmu-columns 城市代码 年份 \
375
+ --input-columns 资本投入 劳动投入 \
376
+ --desirable-output-columns GDP 财政收入 \
377
+ --undesirable-output-columns 工业废水排放量 \
378
+ --orientation input \
379
+ --returns-to-scale crs \
380
+ --score-mode super \
381
+ --result-file radial_results.csv
382
+ ```
383
+
384
+ ```bash
385
+ python additive_models.py sample_data.csv \
386
+ --dmu-columns 城市代码 年份 \
387
+ --input-columns 资本投入 劳动投入 \
388
+ --desirable-output-columns GDP 财政收入 \
389
+ --undesirable-output-columns 工业废水排放量 \
390
+ --model ram \
391
+ --returns-to-scale vrs \
392
+ --result-file ram_results.csv
393
+ ```
394
+
395
+ ```bash
396
+ python directional_distance.py sample_data.csv \
397
+ --dmu-columns 城市代码 年份 \
398
+ --input-columns 资本投入 劳动投入 \
399
+ --desirable-output-columns GDP 财政收入 \
400
+ --undesirable-output-columns 工业废水排放量 \
401
+ --direction proportional \
402
+ --returns-to-scale crs \
403
+ --result-file ddf_results.csv
404
+ ```
405
+
406
+ 加权 SBM 示例(投入块权重顺序为投入列 + 非期望产出列):
407
+
408
+ ```bash
409
+ python super_sbm.py sample_data.csv \
410
+ --dmu-columns 城市代码 年份 \
411
+ --input-columns 资本投入 劳动投入 \
412
+ --desirable-output-columns GDP 财政收入 \
413
+ --undesirable-output-columns 工业废水排放量 \
414
+ --input-weights 2 1 1 \
415
+ --output-weights 1 1 \
416
+ --result-file weighted_sbm_results.csv
417
+ ```
418
+
419
+ 阶段三脚本的快速示例(内置演示数据):
420
+
421
+ ```bash
422
+ python cross_efficiency.py --demo --objective benevolent --matrix-file cross_matrix.csv
423
+ python context_dependent_dea.py --demo --distance 2 --returns-to-scale crs
424
+ python bootstrap_dea.py --demo --repetitions 50 --seed 42 --confidence 0.95
425
+ ```
426
+
427
+ 阶段四环境/面板脚本的快速示例:
428
+
429
+ ```bash
430
+ python undesirable_sbm.py --demo --returns-to-scale vrs
431
+ python weak_disposability_ddf.py --demo --returns-to-scale vrs
432
+ python meta_frontier.py --demo --returns-to-scale crs
433
+ python malmquist_index.py --demo --index ml --returns-to-scale crs
434
+ ```
435
+
436
+ 阶段五面板脚本的快速示例:
437
+
438
+ ```bash
439
+ python window_analysis.py --demo --window 2 --returns-to-scale crs
440
+ python dynamic_sbm.py --demo --returns-to-scale crs
441
+ python malmquist_index.py --demo --index ml --frontier global
442
+ ```
443
+
444
+ 阶段六网络脚本的快速示例:
445
+
446
+ ```bash
447
+ python two_stage_dea.py --demo
448
+ ```
449
+
450
+ 阶段七进阶脚本的快速示例:
451
+
452
+ ```bash
453
+ python three_stage_dea.py --demo --returns-to-scale vrs
454
+ python inverse_dea.py --demo --factor 1.1
455
+ python dea_tobit.py --demo
456
+ python weight_restricted_dea.py --demo
457
+ python by_production.py --demo
458
+ python interval_dea.py --demo --mode fuzzy --uncertainty 0.1
459
+ python stochastic_dea.py --demo --sigma 0.1 --simulations 500 --seed 7
460
+ ```
461
+
462
+ 所有脚本的数据参数一致:`--dmu-columns`、`--input-columns`、`--desirable-output-columns`、`--undesirable-output-columns`、`--sheet`、`--result-file`、`--demo`;面板/网络/进阶脚本另支持 `--period-column`、`--entity-columns`、`--group-column`、`--good-carry-over-columns`、`--bad-carry-over-columns`、`--intermediate-columns`、`--environment-columns`。SBM 另有 `--returns-to-scale/--rts`、`--score-mode/--mode`、`--tolerance/--tol`、`--input-weights`、`--output-weights`;径向模型另有 `--orientation/--orient`;加性族另有 `--model`;DDF 另有 `--direction`;交叉效率另有 `--objective`、`--matrix-file`;Context-dependent 另有 `--distance`;Bootstrap 另有 `--repetitions`、`--confidence`、`--seed`、`--bandwidth`;Malmquist 另有 `--index`、`--frontier`;窗口分析另有 `--window`;Inverse DEA 另有 `--factor`;Tobit 另有 `--censor-limit`;By-production 另有 `--polluting-input-columns`;区间/模糊 DEA 另有 `--mode`、`--uncertainty`;随机 DEA 另有 `--sigma`、`--simulations`、`--seed`;权重约束模型的上下界在配置区 `INPUT_WEIGHT_BOUNDS`、`OUTPUT_WEIGHT_BOUNDS` 中设置。旧短选项(`--dmu-cols`、`--inputs`、`--outputs`、`--bad-outputs`、`--rts`、`--mode`、`--tol`、`--out`)保留为别名。
463
+
464
+ 4. 运行测试:
465
+
466
+ ```bash
467
+ python -m unittest discover -s tests -v
468
+ ```
469
+
470
+ 当前共 147 项测试。`tests/golden/` 保存 `super_sbm.py` 的既有输出基线;只有确认输出应当变化时,才手动运行 `python tests/generate_goldens.py` 更新基线。
471
+
472
+ ## 数据示例
473
+
474
+ `sample_data.csv` 为 4 个城市 × 3 年的面板示例:
475
+
476
+ ```csv
477
+ 城市代码,年份,区域,资本投入,劳动投入,GDP,财政收入,工业废水排放量,资本存量,工业增加值,产业结构
478
+ 110000,2021,北部,800,600,1000,300,120,3000,500,0.52
479
+ ...
480
+ ```
481
+
482
+ `区域` 列用于共同前沿/分组分析;`资本存量` 用作动态 SBM 的好结转变量;`工业增加值` 用作两阶段网络 DEA 的中间产品;`产业结构` 用作三阶段 DEA/DEA-Tobit 的环境变量;Malmquist 需要 `年份` 与 `城市代码` 作为期别/实体列。
483
+
484
+ 当前所有脚本都要求指标为正数;非期望产出为 0 时需先处理(例如替换为很小的正数,或改用其他模型)。
485
+
486
+ ## 说明
487
+
488
+ - 多数脚本把非期望产出按“投入方向”并入投入块;严格非期望产出模型在 `undesirable_sbm.py` 中把非期望产出作为“越少越好的产出”处理。
489
+ - 标准得分 ≤ 1;超效率阶段对有效单元给出 ≥ 1 的得分,得分等于 1 表示未能进一步区分。
490
+ - VRS 径向超效率可能不可行(有效单元在剔除自身后无可行参考组合),此时超效率列留空并提示。
491
+ - 非导向标准 SBM 与增强 Russell 测度(ERM)公式相同,`super_sbm.py --score-mode standard` 即 ERM;加权 SBM 是本项目对 SBM 的权重扩展。
492
+ - Additive 的目标值是松弛和(0 为有效,单位依赖),不提供 0-1 得分;RAM 是加性模型的极差加权版本,默认且要求 VRS。
493
+ - DDF 报告 β(0 为有效);比例方向对指标尺度不变,单位方向要求指标单位可比。弱可处置性 DDF 把非期望产出作为等式约束处理。
494
+ - 交叉效率使用 CCR(CRS)乘数型;交叉效率均值对每一列在所有评价者(含自评)上取平均,进取/仁慈二级目标用于在自评效率相同时确定权重。
495
+ - Context-dependent DEA 使用输出导向分层;吸引力 A 相对更差层,进步 P 相对更好层,边界层或不可行时留空。
496
+ - Bootstrap 为同质平滑 bootstrap,不处理环境变量或异质前沿;默认带宽为 Silverman 经验规则,正式分析建议 B ≥ 1000,偏差校正得分可能超过 1。
497
+ - 共同前沿要求分组列;Malmquist/ML 要求平衡面板(每个实体在每个期别都有观测)。ML 的 DDF 允许 β 为负以处理混合期参考技术;全局模式使用跨期合并前沿。
498
+ - 窗口分析对每个窗口内所有实体-期别观测做投入导向径向 DEA;动态 SBM 要求平衡面板,好/坏结转变量须为正数,且当前实现只包含好/坏结转(不含 free/fixed 结转)。
499
+ - 两阶段网络 DEA 为 CRS 串行 Kao–Hwang 合作式模型,中间产品使用共同乘数连接;阶段效率在整体效率固定后最大化阶段 1 得到,乘数非唯一时分解可能不唯一。当前不含共享投入、阶段 2 额外投入和非期望产出(若数据含非期望产出列,报表会提示已忽略)。
500
+ - 三阶段 DEA 使用半正态 SFA 分解投入松弛;阶段 3 采用向上调整(最差环境与最差运气)。当前不纳入非期望产出。
501
+ - Inverse DEA 是比例投入反推(α×原投入),不是逐项非比例反推;DEA-Tobit 使用上限 1 的右截断 MLE,标准误由数值 Hessian 计算。
502
+ - 权重约束模型为 CRS 乘数型,比例界以第一项指标为基准;By-production 为简化版:T1 运营效率 + T2 污染性投入不扩张下的非期望产出比率,二者等权合成。
503
+ - 区间/模糊 DEA 的端点效率按“自身最差/最好、参考集相反端点”定义;CRS 上界可超过 1,VRS 端点可能不可行(留空并提示)。随机 DEA 的乘性扰动为对数正态(中位数 1),模拟结果依赖 `SIGMA`、模拟次数与随机种子,正式分析建议模拟次数 ≥ 500。
504
+ - Min-max SBM 暂不实现:文献中该名称至少对应两种差异很大的模型——SBM-Max(Sueyoshi–Seki,枚举参考集子集取最大效率的排序方法)与区间/稳健 min-max(针对不确定数据或权重最小化最坏情形效率)。两者的决策变量、约束与输出含义均不同,无法由一个脚本合理覆盖,故未纳入工具包。
505
+ - 公共逻辑集中在 `dea_core.py`;新增模型时复用其中的数据读取、报表与线性规划工具,模型数学留在各自脚本。
506
+
507
+ ## 模型路线图
508
+
509
+ | 阶段 | 方法 | 脚本 | 状态 |
510
+ | --- | --- | --- | --- |
511
+ | 已完成 | 标准 SBM、超效率 SBM、加权 SBM | `super_sbm.py` | 已实现 |
512
+ | 已完成 | ERM(与标准 SBM 等价) | `super_sbm.py --score-mode standard` | 已实现 |
513
+ | 已完成 | CCR、BCC 径向模型 | `radial_models.py` | 已实现 |
514
+ | 已完成 | Additive、RAM | `additive_models.py` | 已实现 |
515
+ | 已完成 | 方向距离函数(DDF) | `directional_distance.py` | 已实现 |
516
+ | 已完成 | 交叉效率 | `cross_efficiency.py` | 已实现 |
517
+ | 已完成 | Context-dependent DEA | `context_dependent_dea.py` | 已实现 |
518
+ | 已完成 | Simar-Wilson Bootstrap DEA | `bootstrap_dea.py` | 已实现 |
519
+ | 已完成 | 严格非期望产出 SBM | `undesirable_sbm.py` | 已实现 |
520
+ | 已完成 | 弱可处置性 DDF | `weak_disposability_ddf.py` | 已实现 |
521
+ | 已完成 | 共同前沿 | `meta_frontier.py` | 已实现 |
522
+ | 已完成 | Malmquist / Malmquist-Luenberger(相邻期/全局) | `malmquist_index.py` | 已实现 |
523
+ | 已完成 | 窗口分析 | `window_analysis.py` | 已实现 |
524
+ | 已完成 | 动态 SBM(好/坏结转) | `dynamic_sbm.py` | 已实现 |
525
+ | 已完成 | 串行两阶段网络 DEA(Kao–Hwang) | `two_stage_dea.py` | 已实现 |
526
+ | 已完成 | 三阶段 DEA(SFA 调整) | `three_stage_dea.py` | 已实现 |
527
+ | 已完成 | Inverse DEA(比例投入反推) | `inverse_dea.py` | 已实现 |
528
+ | 已完成 | DEA-Tobit | `dea_tobit.py` | 已实现 |
529
+ | 已完成 | 权重约束(Assurance Region) | `weight_restricted_dea.py` | 已实现 |
530
+ | 已完成 | By-production(简化) | `by_production.py` | 已实现 |
531
+ | 已完成 | 区间 / 模糊 DEA | `interval_dea.py` | 已实现 |
532
+ | 已完成 | 随机 DEA(蒙特卡洛) | `stochastic_dea.py` | 已实现 |
533
+ | 未实现 | Min-max SBM | — | 暂不实现(两种文献含义差异过大,见“说明”) |