├── LICENSE
├── README.md
├── REFIT_processed
└── RAW_House1_1T_processed.zip
├── REFIT_source
├── RAW_READ_ME_081116.txt
└── REFIT_RAW_081116
│ └── REFIT_RAW_081116.zip
├── TCN_w12.sh
├── TCN_w192.sh
├── TCN_w24.sh
├── TCN_w384.sh
├── TCN_w48.sh
├── TCN_w6.sh
├── TCN_w96.sh
├── data_process.ipynb
├── image
├── Cure.jpg
├── Dilated_Causal_Conv.png
├── ResultTable.jpg
├── SourceData.png
├── SourceDataTable.jpg
├── TCN.png
├── cure2.jpg
└── line.jpg
├── model.py
├── requirements.txt
├── result.ipynb
├── tools.py
├── train_univariate.py
└── vmd.py
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright 2023 梁显武
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 基于深度学习的电力负荷预测算法研究
2 | > 作者:物联 192 梁显武
3 | > 指导老师: 曹忠
4 |
5 | 本代码为本人本科毕业设计的一部分。
6 |
7 |
8 |
9 | ## 基于TCN的电力负荷预测框架
10 |
11 | TCN 不像图像卷积那样通过池化层扩大感受野,而是通过增大扩张因子以及增加层数对感受野进行扩大,这使得它能够接受更长的历史时序信息,从而降低预测的误差、提高准确率。通过残差连接能够使得网络的层数加深而不丢失准确性,这种跨层连接的结构使得信息可以在神经网络的不同层之间直接传递,而不会受到层数的限制,从而提高了神经网络的训练效率和准确性。TCN 的结构主要包括扩张因果卷积以及残差连接组成。
12 |
13 | 
14 |
图1 扩张因果卷积
15 |
16 | 
17 | 图2 基于TCN的电力负荷预测
18 |
19 |
20 |
21 | ## 代码依赖
22 |
23 | * python3.8
24 | * keras==2.6.0
25 | * matplotlib==3.5.2
26 | * numpy==1.19.4
27 | * pandas==1.4.3
28 | * tensorflow==2.6.0
29 |
30 |
31 | 可以使用以下命令安装依赖项:
32 | `pip install -r requirements.txt`
33 |
34 |
35 |
36 | ## 实验平台
37 |
38 | CPU:Xeon(R) CPU E5-2620 v4 @ 2.10GHz
39 | GPU:NVIDIA TITAN V
40 |
41 |
42 |
43 | ## 数据
44 |
45 | 本文使用了一个名为 REFIT 的公开数据集。REFIT数据集是由斯特拉斯克莱德大学、拉夫堡大学和东安格利亚大学合作创建的,数据集包含了 2013 年至 2014 年期间在拉夫堡地区的 20 个家庭的负荷数据由于数据量过大,本文的工作仅仅基于House1的数据进行的。
46 |
47 | 本文所使用的原始数据可以在`REFIT_source`文件夹中找到,经过预处理(数据清洗)之后的数据可以在`REFIT_processed`文件夹中找到。然后在脚本`data_process.ipynb`中对数据进行了清洗工作。
48 | > 注意代码库里面的数据是用压缩形式保存的.zip,使用前需要将压缩包解压到当前文件夹中。
49 |
50 | 原始数据:
51 | 
52 | 
53 |
54 | ## 复现
55 |
56 | 所有的训练设置都已经在`.sh`脚本文件中配置好了,例如`TCN_w6.sh`表示使用处理好的数据对TCN、LSTM、DNN模型进行训练和预测,最终生成的结果将存放在`tuning_w6`文件夹中。如果要复现结果,直接在命令行中输入以下命令。
57 | 1. `TCN_w6.sh`
58 | 2. `TCN_w12.sh`
59 | 3. `TCN_w24.sh`
60 | 4. `TCN_w48.sh`
61 | 5. `TCN_w96.sh`
62 | 6. `TCN_w192.sh`
63 | 7. `TCN_w384.sh`
64 |
65 |
66 |
67 | ## 代码使用
68 |
69 | 代码文件的功能解释如下:
70 | 1. `data_process.ipynb` : 数据处理代码
71 | 2. `model.py` : 模型构建代码
72 | 3. `tools.py` : 模型评估方法和数据归一化方法
73 | 4. `train_univariate.py`: 训练代码
74 | 5. `result.ipynb`:查看结果代码
75 |
76 | 模型训练的代码使用如下:
77 | `python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
78 | `
79 | 参数解释:
80 |
81 | 1. --data 训练数据的文件路径
82 | 2. --target 预测目标曲线
83 | 3. --window_size 数据窗口大小
84 | 4. --model 模型选择
85 | 5. --layer TCN模型的层数
86 | 6. --patience 早停止策略的容忍度
87 | 7. --save 训练结果保存的文件夹
88 | 8. --epoch 训练迭代轮数
89 | 9. --batchsize 批次大小
90 | 10. --lr 学习率大小
91 | 11. --gpu GPU编号
92 |
93 |
94 |
95 | ## 结果
96 |
97 | ### 训练结果表
98 | 每个训练结果都会保存到--save指定的文件夹中,例如`tuning_w6/`。使用`.sh`脚本所产生的结果如下:
99 | 
100 |
101 |
102 | ### 窗口的影响
103 | TCN 的对更长的历史窗口的信息捕获能力表现得更为明显,随着窗口增加,精度呈现出下降趋势,在窗口大小为 386 时预测误差达到了最小。
104 | 
105 |
106 |
107 |
108 |
109 | ### 历史窗口大小为 48时,在曲线上模型预测的具体表现。
110 |
111 | 窗口为48时,Aggregate曲线
112 | 
113 |
114 |
115 |
116 | 窗口为48时Appliance1曲线
117 | 
118 |
119 |
120 | ## 参考论文
121 | [Bai S, Kolter J Z, Koltun V. An empirical evaluation of generic convolutional and recurrent networks for sequence modeling[J]. arXiv preprint arXiv:1803.01271, 2018.](https://arxiv.org/abs/1803.01271)
--------------------------------------------------------------------------------
/REFIT_processed/RAW_House1_1T_processed.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/REFIT_processed/RAW_House1_1T_processed.zip
--------------------------------------------------------------------------------
/REFIT_source/RAW_READ_ME_081116.txt:
--------------------------------------------------------------------------------
1 | REFIT: Electrical Load Measurements
2 |
3 | THE FOLLOWING DATASET IS COMPLETELY RAW APART FROM ACCOUNTING FOR DAYLIGHT SAVINGS TIME (UK)
4 |
5 | INFORMATION
6 | Collection of this dataset was supported by the Engineering and Physical Sciences Research Council (EPSRC) via the project entitled Personalised Retrofit Decision Support Tools for UK Homes using Smart Home Technology (REFIT), under Grant Reference EP/K002368/1 to the University of Strathclyde. REFIT is a collaboration among the Universities of Strathclyde, Loughborough and East Anglia. The dataset includes data from 20 households from the Loughborough area over the period 2013 - 2014. Key findings of the study are available at http://gtr.rcuk.ac.uk/projects?ref=EP%2FK002368%2F1.
7 |
8 | LICENCING
9 | This work is licensed under the Creative Commons Attribution 4.0 International Public License. See https://creativecommons.org/licenses/by/4.0/legalcode for further details.
10 | Please cite the following paper if you use the dataset:
11 |
12 | @inbook{278e1df91d22494f9be2adfca2559f92,
13 | title = "A data management platform for personalised real-time energy feedback",
14 | keywords = "smart homes, real-time energy, smart energy meter, energy consumption, Electrical engineering. Electronics Nuclear engineering, Electrical and Electronic Engineering",
15 | author = "David Murray and Jing Liao and Lina Stankovic and Vladimir Stankovic and Richard Hauxwell-Baldwin and Charlie Wilson and Michael Coleman and Tom Kane and Steven Firth",
16 | year = "2015",
17 | booktitle = "Proceedings of the 8th International Conference on Energy Efficiency in Domestic Appliances and Lighting",
18 | }
19 |
20 | Each of the houses is labelled, House 1 - House 21 (skipping House 14), each house has 10 power sensors comprising a current clamp for the household aggregate and 9 Individual Appliance Monitors (IAMs). Only active power in Watts is collected at 8-second interval.
21 | The subset of all appliances in a household that was monitored reflects the document from DECC of the largest consumers in UK households, https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/274778/9_Domestic_appliances__cooking_and_cooling_equipment.pdf
22 |
23 | FILE FORMAT
24 | The file format is csv and is laid out as follows;
25 | DATETIME, UNIX TIMESTAMP (UCT), Aggregate, Appliance1, Appliance2, Appliance3, ... , Appliance9
26 | Additionally data was only recorded when there was a change in load; this data has been filled with intermediate values where not available. The sensors are also not synchronised as our collection script polled every 6-8 seconds; the sensor may have updated anywhere in the last 6-8 seconds.
27 | The file name _Part1 refers to the first iteration of the database where sensors that were not available were set to 0.
28 | The file name _Part2 refers to the second iteration of the database where sensors that were not available were set to NaN to distinguish from 0.
29 |
30 | MISSING DATA
31 | During the course of the study there are a few periods of missing data (notably February 2014). Outages were due to a number of factors, including household internet failure, hardware failures, network routing issues, etc.
32 |
33 | Household Information
34 | House, Occupancy, Construction Year, Appliances Owned, Type, Size
35 | 1 , 2 , 1975-1980 , 35 , Detached , 4 bed
36 | 2 , 4 , - , 15 , Semi-detached , 3 bed
37 | 3 , 2 , 1988 , 27 , Detached , 3 bed
38 | 4 , 2 , 1850-1899 , 33 , Detached , 4 bed
39 | 5 , 4 , 1878 , 44 , Mid-terrace , 4 bed
40 | 6 , 2 , 2005 , 49 , Detached , 4 bed
41 | 7 , 4 , 1965-1974 , 25 , Detached , 3 bed
42 | 8 , 2 , 1966 , 35 , Detached , 2 bed
43 | 9 , 2 , 1919-1944 , 24 , Detached , 3 bed
44 | 10 , 4 , 1919-1944 , 31 , Detached , 3 bed
45 | 11 , 1 , 1945-1964 , 25 , Detached , 3 bed
46 | 12 , 3 , 1991-1995 , 26 , Detached , 3 bed
47 | 13 , 4 , post 2002 , 28 , Detached , 4 bed
48 | 15 , 1 , 1965-1974 , 19 , Semi-detached , 3 bed
49 | 16 , 6 , 1981-1990 , 48 , Detached , 5 bed
50 | 17 , 3 , mid 60s , 22 , Detached , 3 bed
51 | 18 , 2 , 1965-1974 , 34 , Detached , 3 bed
52 | 19 , 4 , 1945-1964 , 26 , Semi-detached , 3 bed
53 | 20 , 2 , 1965-1974 , 39 , Detached , 3 bed
54 | 21 , 4 , 1981-1990 , 23 , Detached , 3 bed
55 |
56 | APPLIANCE LIST
57 | The following list shows the appliances that were known to be monitored at the beginning of the study period. Although occupants were asked not to remove or switch appliances monitored by the IAMs, we cannot guarantee this to be the case. It should also be noted that Television and Computer Site may consist of multiple appliances, e.g. Television, SkyBox, DvD Player, Computer, Speakers, etc. Makes and Models specified here are gathered from pictures gathered by the installation team.
58 |
59 | House 1
60 | 0.Aggregate
61 | 1.Fridge, Hotpoint, RLA50P
62 | 2.Freezer(1),Beko, CF393APW
63 | 3.Freezer(2), Unknown, Unknown
64 | 4.Washer Dryer, Creda, T522VW
65 | 5.Washing Machine, Beko, WMC6140
66 | 6.Dishwasher, Bosch, Unknown
67 | 7.Computer, Lenovo, H520s
68 | 8.Television Site, Toshiba, 32BL502b
69 | 9.Electric Heater, GLEN, 2172
70 |
71 | House 2
72 | 0.Aggregate,
73 | 1.Fridge-Freezer, Unknown, Unknown
74 | 2.Washing Machine, LG, F1289TD
75 | 3.Dishwasher, Unknown, Unknown
76 | 4.Television Site,
77 | 5.Microwave, Unknown, Unknown
78 | 6.Toaster, Unknown, Unknown
79 | 7.Hi-Fi, Unknown, Unknown
80 | 8.Kettle, Unknown, Unknown
81 | 9.Overhead Fan
82 |
83 | House 3
84 | 0.Aggregate,
85 | 1.Toaster, Dualit, DPP2
86 | 2.Fridge-Freezer, Whirlpool, ARC7612
87 | 3.Freezer, Frigidaire, Freezer Elite
88 | 4.Tumble Dryer, Unknown, Unknown
89 | 5.Dishwasher, Bosch, Exxcel Auto Option
90 | 6.Washing Machine, Unknown, Unknown
91 | 7.Television Site, Samsung, LE46A656A1FXXU
92 | 8.Microwave, Panasoinc, NN-CT565MBPQ
93 | 9.Kettle, Dualit, JKt3
94 |
95 | House 4
96 | 0.Aggregate,
97 | 1.Fridge, Neff, K1514X0GB/31
98 | 2.Freezer, Ocean, UF 1025
99 | 3.Fridge-Freezer, Ariston, DF230
100 | 4.Washing Machine(1), Servis, 6065
101 | 5.Washing Machine(2), Zanussi, Z917
102 | 6.Desktop Computer, Unknown, Unknown
103 | 7.Television Site, Sony, KDL-32W706B
104 | 8.Microwave, Matsui, 170TC
105 | 9.Kettle, Swan, Unknown
106 |
107 | House 5
108 | 0.Aggregate,
109 | 1.Fridge-Freezer, Fisher & Paykel, Unknown
110 | 2.Tumble Dryer, Unknown, Unknown
111 | 3.Washing Machine, AEG, L99695HWD
112 | 4.Dishwasher, Unknown, Unknown
113 | 5.Desktop Computer, Unknown, Unknown
114 | 6.Television Site, Unknown, Unknown
115 | 7.Microwave, Unknown, Unknown
116 | 8.Kettle, Logik, L17SKC14
117 | 9.Toaster, Breville, TT33
118 |
119 | House 6
120 | 0.Aggregate,
121 | 1.Freezer, Whirlpool, CV128W
122 | 2.Washing Machine, Bosch, Classixx 1200 Express
123 | 3.Dishwasher, Neff, Unknown
124 | 4.MJY Computer, Unknown, Unknown
125 | 5.TV/Satellite, Samsung, UE55F6500SB
126 | 6.Microwave, Neff, H5642N0GB/02
127 | 7.Kettle, ASDA, GPK101W
128 | 8.Toaster, Breville, PT15
129 | 9.PGM Computer, Unknown, Unknown
130 |
131 | House 7
132 | 0.Aggregate,
133 | 1.Fridge, Bosch, KSR30422GB
134 | 2.Freezer(1), Whirlpool, AFG 392/H
135 | 3.Freezer(2), Unknown, Unknown
136 | 4.Tumble Dryer, White Knight, Unknown
137 | 5.Washing Machine, Bosch, Unknown
138 | 6.Dishwasher, Unknown, Unknown
139 | 7.Television Site,
140 | 8.Toaster, Unknown, Unknown
141 | 9.Kettle, Sainsburys, 121988254
142 |
143 | House 8
144 | 0.Aggregate,
145 | 1.Fridge, Liebherr, KP2620
146 | 2.Freezer, Unknown, Unknown
147 | 3.Washer Dryer, Zanussi, Unknown
148 | 4.Washing Machine,
149 | 5.Toaster, Bosch, TAT6101GB/02
150 | 6.Computer, Unknown, Unknown
151 | 7.Television Site, Sony, KDL-32V2000
152 | 8.Microwave, Panasoinc, NN-CT565MBPQ
153 | 9.Kettle, Morphy Richards, 43615
154 |
155 | House 9
156 | 0.Aggregate,
157 | 1.Fridge-Freezer, Bosch, KGH34X05GB/05
158 | 2.Washer Dryer, Hotpoint, TCM580
159 | 3.Washing Machine, Bosch, Classixx 6 1200 Express
160 | 4.Dishwasher, Bosch, Classixx
161 | 5.Television Site, LG, 32LH3000
162 | 6.Microwave, Argos, MM717CFA
163 | 7.Kettle, Russel Hobbs, Unknown
164 | 8.Hi-Fi, Unknown, Unknown
165 | 9.Electric Heater
166 |
167 | House 10
168 | 0.Aggregate,
169 | 1.Magimix(Blender), Unknown, Unknown
170 | 2.Toaster, Unknown, Unknown
171 | 3.Chest Freezer, Unknown, Unknown
172 | 4.Fridge-Freezer, Unknown, Unknown
173 | 5.Washing Machine, Beko, WI1382
174 | 6.Dishwasher, AEG, Unknown
175 | 7.Television Site, Samsung, UE40ES5500K
176 | 8.Microwave, Unknown, Unknown
177 | 9.K Mix, Unknown, Unknown
178 |
179 | House 11
180 | 0.Aggregate,
181 | 1.Fridge, Gorenje, HPI 1566
182 | 2.Fridge-Freezer, Unknown, Unknown
183 | 3.Washing Machine, Unknown, Unknown
184 | 4.Dishwasher, Unknown, Unknown
185 | 5.Computer Site, Unknown, Unknown
186 | 6.Microwave, Unknown, Unknown
187 | 7.Kettle, Unknown, Unknown
188 | 8.Router, Unknown, Unknown
189 | 9.Hi-Fi, Unknown, Unknown
190 |
191 | House 12
192 | 0.Aggregate,
193 | 1.Fridge-Freezer, Gorenje, HZS 3266
194 | 2.???, Unknown, Unknown
195 | 3.???, Unknown, Unknown
196 | 4.Computer Site, Unknown, Unknown
197 | 5.Microwave, Unknown, Unknown
198 | 6.Kettle, Unknown, Unknown
199 | 7.Toaster, Unknown, Unknown
200 | 8.Television, Unknown, Unknown
201 | 9.???, Unknown, Unknown
202 |
203 | House 13
204 | 0.Aggregate,
205 | 1.Television Site, Samsung, UE55H6400AK
206 | 2.Freezer, Unknown, Unknown
207 | 3.Washing Machine, Unknown, Unknown
208 | 4.Dishwasher, Unknown, Unknown
209 | 5.???, Unknown, Unknown
210 | 6.Network Site, Unknown, Unknown
211 | 7.Microwave, Unknown, Unknown
212 | 8.Microwave, Unknown, Unknown
213 | 9.Kettle, Unknown, Unknown
214 |
215 | House 15
216 | 0.Aggregate,
217 | 1.Fridge-Freezer, Unknown, Unknown
218 | 2.Tumble Dryer, Unknown, Unknown
219 | 3.Washing Machine, Beko, WMB91242LB
220 | 4.Dishwasher, Unknown, Unknown
221 | 5.Computer Site, Unknown, Unknown
222 | 6.Television Site, LG, 22LS4D
223 | 7.Microwave, Unknown, Unknown
224 | 8.Hi-Fi, Unknown, Unknown
225 | 9.Toaster, Unknown, Unknown
226 |
227 | House 16
228 | 0.Aggregate,
229 | 1.Fridge-Freezer(1), Bosch, KGN30VW20G/01
230 | 2.Fridge-Freezer(2), Unknown, Unknown
231 | 3.Electric Heater(1), Unknown, Unknown
232 | 4.Electric Heater(2), Unknown, Unknown
233 | 5.Washing Machine, Bosch, WAB24262GB/01
234 | 6.Dishwasher, Unknown, Unknown
235 | 7.Computer Site, Unknown, Unknown
236 | 8.Television Site, Samsung, UE55HU8500T
237 | 9.Dehumidifier, Unknown, Unknown
238 |
239 | House 17
240 | 0.Aggregate,
241 | 1.Freezer, Unknown, Unknown
242 | 2.Fridge-Freezer, Whirlpool, ARC 2990
243 | 3.Tumble Dryer, Unknown, Unknown
244 | 4.Washing Machine, Bosch, Exxcel 8 Vario Perfect
245 | 5.Computer Site, Unknown, Unknown
246 | 6.Television Site, Unknown, Unknown
247 | 7.Microwave, Matsui, M195T
248 | 8.Kettle, Russel Hobbs, 17869
249 | 9.TV Site(Bedroom), Unknown, Unknown
250 |
251 | House 18
252 | 0.Aggregate,
253 | 1.Fridge(garage), LEC, R.403W
254 | 2.Freezer(garage), Unknown, Unknown
255 | 3.Fridge-Freezer, Unknown, Unknown
256 | 4.Washer Dryer(garage), Unknown, Unknown
257 | 5.Washing Machine, Unknown, Unknown
258 | 6.Dishwasher, Unknown, Unknown
259 | 7.Desktop Computer, Unknown, Unknown
260 | 8.Television Site, Unknown, Unknown
261 | 9.Microwave, Unknown, Unknown
262 |
263 | House 19
264 | 0.Aggregate,
265 | 1.Fridge Freezer, Bosch, KGS-3272-GB/01
266 | 2.Washing Machine, Bosch, WAE24060GB/03
267 | 3.Television Site, Sony, KDL32EX703
268 | 4.Microwave, Kenwood, K20MSS10
269 | 5.Kettle, Breville, VKJ336
270 | 6.Toaster, Bellini, BET240
271 | 7.Bread-maker, Unknown, Unknown
272 | 8.Games Console, Unknown, Unknown
273 | 9.Hi-Fi, Unknown, Unknown
274 |
275 | House 20
276 | 0.Aggregate,
277 | 1.Fridge, Unknown, Unknown
278 | 2.Freezer, Unknown, Unknown
279 | 3.Tumble Dryer, Unknown, Unknown
280 | 4.Washing Machine, Unknown, Unknown
281 | 5.Dishwasher, Unknown, Unknown
282 | 6.Computer Site, Unknown, Unknown
283 | 7.Television Site, Unknown, Unknown
284 | 8.Microwave, Unknown, Unknown
285 | 9.Kettle, Unknown, Unknown
286 |
287 | House 21
288 | 0.Aggregate,
289 | 1.Fridge-Freezer, Samsung, SR-L3216B
290 | 2.Tumble Dryer, Unknown, Unknown
291 | 3.Washing Machine, Beko, WMB81241LW
292 | 4.Dishwasher, AEG, FAVORIT
293 | 5.Food Mixer, Unknown, Unknown
294 | 6.Television, Unknown, Unknown
295 | 7.Kettle, Unknown, Unknown
296 | 8.Vivarium, Unknown, Unknown
297 | 9.Pond Pump, Unknown, Unknown
--------------------------------------------------------------------------------
/REFIT_source/REFIT_RAW_081116/REFIT_RAW_081116.zip:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/REFIT_source/REFIT_RAW_081116/REFIT_RAW_081116.zip
--------------------------------------------------------------------------------
/TCN_w12.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 12 --model TCN --layer 3 --patience 10 --save tuning_w12/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 12 --model ANN --patience 10 --save tuning_w12/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 12 --model LSTM --patience 10 --save tuning_w12/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 1
36 |
--------------------------------------------------------------------------------
/TCN_w192.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 192 --model TCN --layer 7 --patience 10 --save tuning_w192/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 192 --model ANN --patience 10 --save tuning_w192/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 192 --model LSTM --patience 10 --save tuning_w192/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
36 |
--------------------------------------------------------------------------------
/TCN_w24.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 24 --model TCN --layer 4 --patience 10 --save tuning_w24/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 24 --model ANN --patience 10 --save tuning_w24/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 24 --model LSTM --patience 10 --save tuning_w24/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 2
36 |
--------------------------------------------------------------------------------
/TCN_w384.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 384 --model TCN --layer 8 --patience 10 --save tuning_w384/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
12 |
13 | # DNN
14 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
15 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
16 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
17 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
18 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
19 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
20 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
21 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
22 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
23 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 384 --model ANN --patience 10 --save tuning_w384/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
24 |
25 | # LSTM
26 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
28 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
29 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
30 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
31 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
32 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
33 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
34 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
35 | # python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 384 --model LSTM --patience 10 --save tuning_w384/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
36 |
--------------------------------------------------------------------------------
/TCN_w48.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 48 --model TCN --layer 5 --patience 10 --save tuning_w48/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 48 --model ANN --patience 10 --save tuning_w48/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 48 --model LSTM --patience 10 --save tuning_w48/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 3
36 |
--------------------------------------------------------------------------------
/TCN_w6.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 6 --model TCN --layer 2 --patience 10 --save tuning_test/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 6 --model ANN --patience 10 --save tuning_test/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 6 --model LSTM --patience 10 --save tuning_test/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 9
36 |
--------------------------------------------------------------------------------
/TCN_w96.sh:
--------------------------------------------------------------------------------
1 | # TCN
2 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
3 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
4 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
5 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
6 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
7 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
8 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
9 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
10 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
11 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 96 --model TCN --layer 6 --patience 10 --save tuning_w96/TCN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
12 |
13 | # DNN
14 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
15 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
16 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
17 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
18 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
19 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
20 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
21 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
22 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
23 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 96 --model ANN --patience 10 --save tuning_w96/ANN_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
24 |
25 | # LSTM
26 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Aggregate --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Aggregate --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
27 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance1 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance1 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
28 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance2 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance2 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
29 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance3 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance3 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
30 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance4 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance4 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
31 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance5 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance5 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
32 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance6 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance6 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
33 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance7 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance7 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
34 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance8 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance8 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
35 | python train_univariate.py --data REFIT_processed/RAW_House1_1T_processed.csv --target Appliance9 --window_size 96 --model LSTM --patience 10 --save tuning_w96/LSTM_Appliance9 --epoch 1000 --batchsize 128 --lr 0.008 --gpu 4
36 |
--------------------------------------------------------------------------------
/image/Cure.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/Cure.jpg
--------------------------------------------------------------------------------
/image/Dilated_Causal_Conv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/Dilated_Causal_Conv.png
--------------------------------------------------------------------------------
/image/ResultTable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/ResultTable.jpg
--------------------------------------------------------------------------------
/image/SourceData.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/SourceData.png
--------------------------------------------------------------------------------
/image/SourceDataTable.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/SourceDataTable.jpg
--------------------------------------------------------------------------------
/image/TCN.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/TCN.png
--------------------------------------------------------------------------------
/image/cure2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/cure2.jpg
--------------------------------------------------------------------------------
/image/line.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/joker507/Power_Load_Forecasting_by_TCN/4b71f0bc31e65bc1ba92c073872ab64ed6b024a0/image/line.jpg
--------------------------------------------------------------------------------
/model.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | import tensorflow.keras as keras
3 | from keras.utils.vis_utils import plot_model
4 |
5 | # TCN残差连接块
6 | def TCN_Block(inputs, dilation_rate, in_channels,
7 | out_channels, padding, kernel_size=2,dropout_rate=0.2):
8 |
9 | init = tf.keras.initializers.RandomNormal(mean=0.0, stddev=0.1)
10 | assert padding in ["causal","same"]
11 |
12 | # block1
13 | conv1 = keras.layers.Conv1D(filters=out_channels, kernel_size=kernel_size, dilation_rate=dilation_rate, padding=padding, kernel_initializer=init)
14 | batch1 = keras.layers.BatchNormalization(axis=-1)
15 | ac1 = keras.layers.Activation("relu")
16 | drop1 = keras.layers.Dropout(rate=dropout_rate)
17 |
18 | # block2
19 | conv2 = keras.layers.Conv1D(filters=out_channels, kernel_size=kernel_size, dilation_rate=dilation_rate, padding=padding, kernel_initializer=init)
20 | batch2 = keras.layers.BatchNormalization(axis=-1)
21 | ac2 = keras.layers.Activation("relu")
22 | drop2 = keras.layers.Dropout(rate=dropout_rate)
23 |
24 | # 输出维度一致
25 | downsample = keras.layers.Conv1D(filters=out_channels,
26 | kernel_size=1,
27 | padding="same",
28 | kernel_initializer=init)
29 |
30 | ac3 = keras.layers.Activation("relu")
31 |
32 | # forward
33 | # inputs = keras.Input(shape=(window_size, in_channels))
34 | x = conv1(inputs)
35 | x = batch1(x)
36 | x = ac1(x)
37 | x = drop1(x)
38 | x = conv2(x)
39 | x = batch2(x)
40 | x = ac2(x)
41 | y = drop2(x)
42 | if in_channels != out_channels:
43 | res = downsample(inputs)
44 | else:
45 | res = inputs
46 |
47 | outputs = ac3(keras.layers.add([y,res]))
48 |
49 | return outputs
50 |
51 | # TCN
52 | def TCN(num_inputs=10 ,num_channels=[150,150,150,150],
53 | window_size=6, kernel_size=2, dropout=0.2):
54 |
55 | # input layers
56 | inputs = keras.Input(shape=(window_size,num_inputs))
57 | t = inputs
58 |
59 | # TCN layers
60 | num_levels = len(num_channels) # 层数
61 | for i in range(num_levels):
62 | dilation_size = 2 ** i
63 | in_channels = num_inputs if i == 0 else num_channels[i-1]
64 | out_channels = num_channels[i]
65 | # tcn clock
66 | t = TCN_Block(t,
67 | dilation_rate=dilation_size,
68 | in_channels=in_channels,
69 | out_channels=out_channels,
70 | padding='causal',
71 | kernel_size=kernel_size,
72 | dropout_rate=dropout)
73 |
74 | # output layers
75 | # outputs = keras.layers.Conv1D(filters=1, kernel_size=3)(outputs)
76 | # outputs = keras.layers.Flatten()(outputs)
77 | outputs = keras.layers.Dense(1,activation=None)(t[:,-1,:]) # (batsize,final_time_step,dim)
78 |
79 | tcn_model = keras.Model(inputs=inputs, outputs=outputs)
80 | tcn_model.compile(optimizer="adam", loss="mse", metrics=["mae"])
81 | tcn_model.summary()
82 | return tcn_model
83 |
84 | # LSTM
85 | def LSTM(window_size,units=12,dim=10):
86 | x = keras.layers.Input(shape=(window_size, dim))
87 | t = keras.layers.LSTM(units=units, return_sequences=False)(x)
88 | y = keras.layers.Dense(1)(t)
89 |
90 | model = keras.Model(inputs=x,outputs=y)
91 | model.summary()
92 | return model
93 |
94 | # GRU
95 | def GRU(window_size):
96 | x = keras.layers.Input(shape=(window_size, 10))
97 | t = keras.layers.GRU(units=12, return_sequences=True)(x)
98 | t = keras.layers.Dropout(0.2)(t)
99 | t = keras.layers.GRU(units=12, return_sequences=False)(t)
100 | t = keras.layers.Dropout(0.2)(t)
101 | y = keras.layers.Dense(1)(t)
102 |
103 | model = keras.Model(inputs=x,outputs=y)
104 | # model.compile(optimizer="adam", loss="mse", metrics=["mae"])
105 | model.summary()
106 | return model
107 |
108 | # ANN(DNN)
109 | def ANN(window_size,dim=10):
110 | x = keras.layers.Input(shape=(window_size,dim))
111 | t = keras.layers.Flatten()(x)
112 | t = keras.layers.Dense(128, activation='sigmoid')(t)
113 | t = keras.layers.Dense(256, activation='sigmoid')(t)
114 | t = keras.layers.Dense(128, activation='sigmoid')(t)
115 | y = keras.layers.Dense(1)(t)
116 |
117 | model = keras.Model(inputs=x,outputs=y)
118 | model.compile(optimizer="adam", loss="mse", metrics=["mae"])
119 | model.summary()
120 | return model
121 |
122 | ## 模型构建
123 | def build_model(model_name, window_size,dim=10, TCN_layers=2):
124 | model_type = model_name
125 | if model_type == "LSTM":
126 | train_model = LSTM(window_size=window_size,units=12,dim=dim)
127 | elif model_type == "ANN":
128 | train_model = ANN(window_size,dim)
129 | elif model_type == "GRU":
130 | train_model = GRU(window_size,units=12)
131 | elif model_type == "TCN":
132 | num_inputs=1
133 | num_channels=[20 for i in range(TCN_layers)]
134 | print("TCN_layers is ", TCN_layers)
135 | kernel_size=3
136 | dropout=0.2
137 | train_model = TCN(num_inputs,num_channels,window_size,kernel_size,dropout)
138 | else:
139 | assert False, "请选择正确的模型"
140 |
141 | return train_model
142 |
143 | if __name__ == "__main__":
144 | window_size = 6
145 | m = ANN(window_size,dim=1)
146 | plot_model(m, 'model.png', show_shapes=True, show_layer_names=True)
147 |
148 |
149 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | keras==2.6.0
2 | matplotlib==3.5.2
3 | numpy==1.19.4
4 | numpy==1.19.5
5 | pandas==1.4.3
6 | tensorflow==2.6.0
7 |
--------------------------------------------------------------------------------
/tools.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | ## 评估指标
4 | def rmse(true,pre):
5 | return np.sqrt(np.mean(np.square(true-pre)))
6 |
7 | def mae(true, pre):
8 | return np.mean(np.abs(true - pre))
9 |
10 | def mse(true,pre):
11 | return np.mean(np.square(true-pre))
12 |
13 | def mape(true, pre):
14 | return np.mean(np.abs((true - pre) / true)) * 100 #单位%
15 |
16 | ## zero-score归一化方法
17 | class Standardscale():
18 | def __init__(self):
19 | self.mean = 0.
20 | self.std = 1.
21 |
22 | def fit(self, data):
23 | self.mean = data.mean(0)
24 | self.std = data.std(0)
25 |
26 | def transform(self, data):
27 | mean = self.mean
28 | std = self.std
29 | return (data - mean) / std
30 |
31 | def inverse_transform(self, data):
32 | mean = self.mean
33 | std = self.std
34 |
35 | # 如果参数是数组,数据是不一样的数组时,采用第一列特征进行放缩
36 | if len(mean.shape) != 0: # 参数不是数值并且与数据长度不一致时转为数值
37 | if data.shape[-1] != mean.shape[-1]:
38 | mean = mean[0]
39 | std = std[0]
40 |
41 | return (data * std) + mean
42 |
43 | ## Max-min最大最小归一化
44 | class Maxminscale():
45 | def __init__(self):
46 | self.min = 0.
47 | self.max = 1.
48 |
49 | def fit(self, data):
50 | self.max = data.max(0)
51 | self.min = data.min(0)
52 |
53 | def transform(self, data):
54 | max = self.max
55 | min = self.min
56 | return (data - min) / (max - min)
57 |
58 | def inverse_transform(self, data):
59 | max = self.max
60 | min = self.min
61 |
62 | if len(max.shape) != 0:
63 | if data.shape[-1] != max.shape[-1]: #如果数据的维度和参数的维度不一致 采用第0个
64 | max = max[0]
65 | min = min[0]
66 | return (data * (max - min)) + min
67 |
68 | ## 无需归一化
69 | class Nonescale():
70 | def __init__(self):
71 | pass
72 |
73 | def fit(self, data):
74 | pass
75 |
76 | def transform(self, data):
77 | return data
78 |
79 | def inverse_transform(self, data):
80 | return data
--------------------------------------------------------------------------------
/train_univariate.py:
--------------------------------------------------------------------------------
1 | from numpy.random import seed
2 | seed(42) ## 设置伪随机序列
3 | from tensorflow.random import set_seed
4 | set_seed(42)
5 |
6 | import argparse
7 | import os
8 | import json
9 | import pandas as pd
10 | import numpy as np
11 | import matplotlib.pyplot as plt
12 | import tensorflow as tf
13 | import tensorflow.keras as keras
14 | from keras.utils.vis_utils import plot_model
15 | from model import build_model
16 | from tools import rmse,mae,mse,mape,Standardscale,Maxminscale,Nonescale
17 | from vmd import VMD
18 |
19 | parser = argparse.ArgumentParser(description="Electrical load curve prediction")
20 | parser.add_argument("--data", type=str, default="REFIT_processed\RAW_House1_12H_processed.csv",
21 | help="a csv file path which include some appliance load data ")
22 | parser.add_argument("--target", type=str, default='Aggregate',
23 | help="predict target cure including Aggregate or Appliancex")
24 | parser.add_argument("--test_rate", type=float, default=0.2,
25 | help="test set rate")
26 | parser.add_argument("--window_size", type=int, default=6,
27 | help="Historical reference length")
28 | parser.add_argument("--scale", type=str, default="standard",
29 | help="data scale for model inputs")
30 | parser.add_argument("--save", type=str, default=os.getcwd()+"/tuning_univariate/",
31 | help="training result folder")
32 | parser.add_argument("--model", type=str, default="CA",
33 | help="Model name")
34 | parser.add_argument("--layer", type=int, default=2,
35 | help="TCN layers")
36 | parser.add_argument("--lr", type=float, default=0.001,
37 | help="learning rate")
38 | parser.add_argument("--vmd", action='store_true',
39 | help="sue vmd to extract feature")
40 | parser.add_argument("--patience",type=int, default=10,
41 | help="early stop")
42 | parser.add_argument("--epoch",type=int, default=1000,
43 | help="training epoch")
44 | parser.add_argument("--batchsize",type=int, default=128,
45 | help="batchsize")
46 | parser.add_argument("--gpu",type=int, default=0,
47 | help="gpu device id")
48 |
49 | args = parser.parse_args()
50 |
51 | gpus = tf.config.list_physical_devices('GPU')
52 | if gpus:
53 | # 设置 TensorFlow 只使用第一块 GPU
54 | try:
55 | tf.config.set_visible_devices(gpus[args.gpu], 'GPU')
56 | logical_gpus = tf.config.experimental.list_logical_devices('GPU')
57 | print(len(gpus), "Physical GPUs,", len(logical_gpus), "Logical GPUs")
58 | except RuntimeError as e:
59 | # 异常处理
60 | print(e)
61 |
62 | if not os.path.exists(args.save):
63 | os.makedirs(args.save)
64 | log_dic = {"data":{}, "model":{}, "traing":{}, "testing":{}}
65 | plot = False
66 |
67 | ####################################################################################
68 | # Load Data
69 | ####################################################################################
70 | def make_data(file_path, test_rate, window_size,scale, target):
71 |
72 | df = pd.read_csv(file_path, parse_dates=["Time"], index_col ="Time")
73 | df = df[target]
74 |
75 | # 切分数据集
76 | test_num = int(len(df) * test_rate)
77 | train_data = df[:-test_num].copy().values
78 | test_data = df[-test_num:].copy().values
79 | print("dataset shape:",df.shape)
80 | print("train_data shape:",train_data.shape)
81 | print("test_data shape:",test_data.shape)
82 |
83 | scale.fit(train_data)
84 | train_data = scale.transform(train_data)
85 |
86 | # 测试集数据归一化
87 | test_data = scale.transform(test_data)
88 |
89 | # 窗口滑动制作数据样本
90 | train_X = []
91 | train_y = []
92 | train_num = train_data.shape[0]
93 | for k in range(train_num-window_size):
94 | train_X.append(train_data[k:k+window_size]) #x: [k:k+window_size)
95 | train_y.append(train_data[k+window_size]) #y: k+windowsize
96 |
97 | test_X = []
98 | test_y = []
99 | test_num = test_data.shape[0]
100 | for k in range(test_num-window_size):
101 | test_X.append(test_data[k:k+window_size]) #x: [k: k+window_size)
102 | test_y.append(test_data[k+window_size]) #y: k+windowsize
103 |
104 | train_X, train_y = np.array(train_X), np.reshape(train_y,(len(train_y),1))
105 | test_X, test_y = np.array(test_X), np.reshape(test_y,(len(test_y),1))
106 |
107 | print("train_x shape: ", train_X.shape)
108 | print("train_y shape: ", train_y.shape)
109 | print("test_x shape: ", test_X.shape)
110 | print("test_y shape: ", test_y.shape)
111 |
112 | return train_X,train_y,test_X,test_y,scale
113 |
114 | scale = Standardscale()
115 | train_X,train_y,test_X,test_y,scale = make_data(args.data, args.test_rate, args.window_size, scale, args.target)
116 | log_dic["data"]["file"] = args.data
117 | log_dic["data"]["target"] = args.target
118 | log_dic["data"]["windows"] = args.window_size
119 |
120 |
121 | ## shuufle
122 | indexes = np.arange(len(train_X))
123 | np.random.shuffle(indexes)
124 | train_X = train_X[indexes]
125 | train_y = train_y[indexes]
126 | log_dic["data"]["seed"] = 42
127 |
128 | ####################################################################################
129 | # extract vmd feature
130 | ####################################################################################
131 |
132 | if args.vmd: # 增加vmd特征提取
133 |
134 | alpha = 2000 # moderate bandwidth constraint
135 | tau = 0. # noise-tolerance (no strict fidelity enforcement)
136 | K = 3 # 3 modes
137 | DC = 0 # no DC part imposed
138 | init = 1 # initialize omegas uniformly
139 | tol = 1e-7
140 |
141 | vmd_train_X = [] # 存储vmd数据
142 | vmd_test_X = []
143 | for i in range(len(train_X)): # for every one example
144 | vmd_compose_matrix , u_hat, omega = VMD(train_X[i], alpha, tau, K, DC, init, tol)
145 | vmd_train_X.append(vmd_compose_matrix.T) # append(shape=(W,3))
146 |
147 | for i in range(len(test_X)): # for every one example
148 | vmd_compose_matrix , u_hat, omega = VMD(test_X[i], alpha, tau, K, DC, init, tol)
149 | vmd_test_X.append(vmd_compose_matrix.T) # append(shape=(W,3))
150 |
151 | train_X = np.expand_dims(train_X, axis=-1)
152 | test_X = np.expand_dims(test_X, axis=-1)
153 | train_X = np.concatenate((train_X,np.array(vmd_train_X)), axis=-1) # (N, W, 1) (N, W, 3) -> (B, W, 4)
154 | test_X = np.concatenate((test_X,np.array(vmd_test_X)), axis=-1)
155 | print(train_X.shape)
156 | print(test_X.shape)
157 | log_dic["data"]["vmd"] = 3
158 | dim = 4 ## 输入维度大小
159 |
160 | else:
161 | train_X = np.expand_dims(train_X, axis=-1)
162 | test_X = np.expand_dims(test_X, axis=-1)
163 | dim = 1 ## 输入维度大小
164 |
165 | log_dic['data']["train_x"] = str(train_X.shape)
166 | log_dic['data']["train_y"] = str(train_y.shape)
167 | log_dic['data']["test_x"] = str(test_X.shape)
168 | log_dic['data']["test_y"] = str(test_y.shape)
169 |
170 | ####################################################################################
171 | # Build Model
172 | ####################################################################################
173 |
174 | train_model = build_model(args.model, args.window_size, dim, TCN_layers=args.layer)
175 | log_dic["model"]["name"] = args.model
176 |
177 | optimizer = keras.optimizers.Adam(learning_rate=args.lr)
178 | log_dic["model"]["lr"] = args.lr
179 |
180 | train_model.compile(optimizer=optimizer, loss="mse", metrics=["mae"])
181 | log_dic["model"]["loss"] = "mse"
182 |
183 | # 绘制模型图
184 | # plot_model(train_model, to_file=os.path.join(args.save, args.model+"_model.png"),
185 | # show_shapes=True,
186 | # show_dtype=True,
187 | # show_layer_names=True)
188 |
189 |
190 | ####################################################################################
191 | # Training Code
192 | ####################################################################################
193 |
194 | callback = keras.callbacks.EarlyStopping(monitor='val_loss', patience=args.patience)
195 | history = train_model.fit(x=train_X, y=train_y,
196 | # train_dataset,
197 | epochs=args.epoch, batch_size=args.batchsize, shuffle=True,
198 | validation_split = 0.2,callbacks=[callback])
199 |
200 | log_dic["traing"]["epoch"] = args.epoch
201 | log_dic["traing"]["batchsize"] = args.batchsize
202 | log_dic["traing"]["early_stop"] = len(history.history["val_loss"])
203 |
204 | epoch = len(history.history["val_loss"])
205 |
206 | # 保存训练好的模型
207 | train_model.save(os.path.join(args.save, args.model+".h5"))
208 |
209 | # 最佳验证集结果:用来挑选超参
210 | val_loss = min(history.history['val_loss'])
211 | val_epoch = history.history['val_loss'].index(val_loss) + 1
212 | val_mae = history.history['val_mae'][val_epoch-1]
213 | train_loss = history.history['loss'][-1]
214 | train_mae = history.history['mae'][-1]
215 | log_dic["traing"]["best_val_mse"] = round(val_loss,3)
216 | log_dic["traing"]["best_val_mae"] = round(val_loss,3)
217 | log_dic["traing"]["best_epoch"] = val_epoch
218 | log_dic["traing"]["final_train_loss"] = round(train_loss,3)
219 | log_dic["traing"]["final_train_mae"] = round(train_mae,3)
220 | log_dic["traing"]["final_val_loss"] = round(history.history['val_loss'][-1],3)
221 | log_dic["traing"]["final_val_mae"] = round(history.history['val_mae'][-1],3)
222 |
223 | ## display
224 | # loss
225 | plt.figure(figsize=(20,10))
226 | plt.plot(history.history['loss'], label="train loss")
227 | plt.plot(history.history['val_loss'], label="val loss")
228 | plt.title(args.model + 'train loss')
229 | plt.ylabel('loss')
230 | plt.xlabel('epoch')
231 | plt.legend(loc='upper right')
232 | plt.savefig(os.path.join(args.save, 'train_loss.jpg'))
233 | if plot:
234 | plt.show()
235 |
236 | ####################################################################################
237 | # Testing Model
238 | ####################################################################################
239 |
240 | train_model = keras.models.load_model(os.path.join(args.save, args.model+".h5"))
241 | print("sucessfully load the model")
242 |
243 | # 测试集评估模型
244 | evaluate_result = train_model.evaluate(x=test_X, y=test_y)
245 | print("Test loss:{}, mae:{}".format(evaluate_result[0],evaluate_result[1]))
246 | log_dic["testing"]["evaluate"] = {"loss":evaluate_result[0], "mae":evaluate_result[1]}
247 |
248 | # 分析预测结果
249 | predicts = train_model.predict(test_X)
250 | predicts_inv = scale.inverse_transform(predicts)
251 | test_predicts = np.reshape(predicts, len(predicts))
252 | test_predicts_inv = np.reshape(predicts_inv, len(predicts))
253 |
254 | trues = test_y
255 | trues_inv = scale.inverse_transform(test_y)
256 | test_trues = np.reshape(trues, (len(trues)))
257 | test_trues_inv = np.reshape(trues_inv, (len(trues_inv)))
258 |
259 | r = rmse(test_trues,test_predicts)
260 | m = mae(test_trues,test_predicts)
261 | ms = mse(test_trues,test_predicts)
262 | mape_t = mape(test_trues,test_predicts)
263 | r_inv = rmse(test_trues_inv,test_predicts_inv)
264 | m_inv = mae(test_trues_inv,test_predicts_inv)
265 | mse_inv = mse(test_trues_inv,test_predicts_inv)
266 | mape_inv = mape(test_trues_inv,test_predicts_inv)
267 | predict_df = pd.DataFrame({
268 | "test_trues":test_trues,
269 | "test_predicts":test_predicts,
270 | "test_trues_inv":test_trues_inv,
271 | "test_predicts_inv":test_predicts_inv
272 | })
273 | predict_df.to_csv(os.path.join(args.save , 'predicts.csv'))
274 |
275 | print("Test set:"+">"*5+args.model+"<"*5)
276 | print("standard result")
277 | print("rmse:",r)
278 | print("mae:",m)
279 | print("mse:",ms)
280 | print("mape:",mape_t)
281 | print("inverter result")
282 | print("rmse:",r_inv)
283 | print("mae:",m_inv)
284 | print("mse:",mse_inv)
285 | print("mape:",mape_inv)
286 |
287 | metrics_df = pd.DataFrame({
288 | "method":["rmse","mae","mse","mape"],
289 | "standard":[r,m,ms,mape_t],
290 | "inverse":[r_inv,m_inv,mse_inv,mape_inv],
291 | })
292 | log_dic["testing"]["standard"] = {"rmse":r, "mse": ms, "mae": m, "mape": mape_t}
293 | log_dic["testing"]["inverse"] = {"rmse":r_inv, "mse": mse_inv, "mae": m_inv, "mape": mape_inv}
294 |
295 | metrics_df.to_csv(os.path.join(args.save,'test_metrics.csv'))
296 |
297 | # predict
298 | plt.figure(figsize=(20,10))
299 | plt.title("standard predict: rmse:{:.2f} mse:{:.2f} mae:{:.2f} mape:{:.2f}".format(r,ms,m,mape_t))
300 | plt.plot(test_trues,'b', label="true")
301 | plt.plot(test_trues,'bo', markersize=3, label="true")
302 | plt.plot(test_predicts,'r', label='predict')
303 | plt.plot(test_predicts,'rx', markersize=5, label='predict')
304 | plt.legend(loc='best')
305 | plt.savefig(os.path.join(args.save, 'standard_predict.jpg'))
306 | if plot:
307 | plt.show()
308 |
309 | plt.figure(figsize=(20,10))
310 | plt.title("inverse predict: rmse:{:.2f} mse:{:.2f} mae:{:.2f} mape:{:.2f}".format(r_inv,mse_inv,m_inv,mape_inv))
311 | plt.plot(test_trues_inv,'b', label="true")
312 | plt.plot(test_trues_inv,'bo', markersize=3, label="true")
313 | plt.plot(test_predicts_inv,'r', label='predict')
314 | plt.plot(test_predicts_inv,'rx', markersize=5, label='predict')
315 | plt.legend(loc='best')
316 | plt.savefig(os.path.join(args.save, 'inverse_predict.jpg'))
317 | if plot:
318 | plt.show()
319 |
320 | ## 保存参数与结果
321 | with open(os.path.join(args.save, 'log.json'),'w') as f:
322 | json.dump(log_dic,f,indent=4)
323 |
324 | print("result dir in: ",os.path.join(args.save))
325 |
--------------------------------------------------------------------------------
/vmd.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import pandas as pd
3 |
4 | def VMD(f, alpha, tau, K, DC, init, tol):
5 | """
6 | u,u_hat,omega = VMD(f, alpha, tau, K, DC, init, tol)
7 | Variational mode decomposition
8 | Python implementation by Vinícius Rezende Carvalho - vrcarva@gmail.com
9 | code based on Dominique Zosso's MATLAB code, available at:
10 | https://www.mathworks.com/matlabcentral/fileexchange/44765-variational-mode-decomposition
11 | Original paper:
12 | Dragomiretskiy, K. and Zosso, D. (2014) ‘Variational Mode Decomposition’,
13 | IEEE Transactions on Signal Processing, 62(3), pp. 531–544. doi: 10.1109/TSP.2013.2288675.
14 |
15 |
16 | Input and Parameters:
17 | ---------------------
18 | f - the time domain signal (1D) to be decomposed
19 | alpha - the balancing parameter of the data-fidelity constraint
20 | tau - time-step of the dual ascent ( pick 0 for noise-slack )
21 | K - the number of modes to be recovered
22 | DC - true if the first mode is put and kept at DC (0-freq)
23 | init - 0 = all omegas start at 0
24 | 1 = all omegas start uniformly distributed
25 | 2 = all omegas initialized randomly
26 | tol - tolerance of convergence criterion; typically around 1e-6
27 |
28 | Output:
29 | -------
30 | u - the collection of decomposed modes
31 | u_hat - spectra of the modes
32 | omega - estimated mode center-frequencies
33 | """
34 |
35 | if len(f) % 2:
36 | f = f[:-1]
37 |
38 | # Period and sampling frequency of input signal
39 | fs = 1. / len(f)
40 |
41 | ltemp = len(f) // 2
42 | fMirr = np.append(np.flip(f[:ltemp], axis=0), f)
43 | fMirr = np.append(fMirr, np.flip(f[-ltemp:], axis=0))
44 |
45 | # Time Domain 0 to T (of mirrored signal)
46 | T = len(fMirr)
47 | t = np.arange(1, T + 1) / T
48 |
49 | # Spectral Domain discretization
50 | freqs = t - 0.5 - (1 / T)
51 |
52 | # Maximum number of iterations (if not converged yet, then it won't anyway)
53 | Niter = 500
54 | # For future generalizations: individual alpha for each mode
55 | Alpha = alpha * np.ones(K)
56 |
57 | # Construct and center f_hat
58 | f_hat = np.fft.fftshift((np.fft.fft(fMirr)))
59 | f_hat_plus = np.copy(f_hat) # copy f_hat
60 | f_hat_plus[:T // 2] = 0
61 |
62 | # Initialization of omega_k
63 | omega_plus = np.zeros([Niter, K])
64 |
65 | if init == 1:
66 | for i in range(K):
67 | omega_plus[0, i] = (0.5 / K) * (i)
68 | elif init == 2:
69 | omega_plus[0, :] = np.sort(np.exp(np.log(fs) + (np.log(0.5) - np.log(fs)) * np.random.rand(1, K)))
70 | else:
71 | omega_plus[0, :] = 0
72 |
73 | # if DC mode imposed, set its omega to 0
74 | if DC:
75 | omega_plus[0, 0] = 0
76 |
77 | # start with empty dual variables
78 | lambda_hat = np.zeros([Niter, len(freqs)], dtype=complex)
79 |
80 | # other inits
81 | uDiff = tol + np.spacing(1) # update step
82 | n = 0 # loop counter
83 | sum_uk = 0 # accumulator
84 | # matrix keeping track of every iterant // could be discarded for mem
85 | u_hat_plus = np.zeros([Niter, len(freqs), K], dtype=complex)
86 |
87 | # *** Main loop for iterative updates***
88 |
89 | while (uDiff > tol and n < Niter - 1): # not converged and below iterations limit
90 | # update first mode accumulator
91 | k = 0
92 | sum_uk = u_hat_plus[n, :, K - 1] + sum_uk - u_hat_plus[n, :, 0]
93 |
94 | # update spectrum of first mode through Wiener filter of residuals
95 | u_hat_plus[n + 1, :, k] = (f_hat_plus - sum_uk - lambda_hat[n, :] / 2) / (
96 | 1. + Alpha[k] * (freqs - omega_plus[n, k]) ** 2)
97 |
98 | # update first omega if not held at 0
99 | if not (DC):
100 | omega_plus[n + 1, k] = np.dot(freqs[T // 2:T], (abs(u_hat_plus[n + 1, T // 2:T, k]) ** 2)) / np.sum(
101 | abs(u_hat_plus[n + 1, T // 2:T, k]) ** 2)
102 |
103 | # update of any other mode
104 | for k in np.arange(1, K):
105 | # accumulator
106 | sum_uk = u_hat_plus[n + 1, :, k - 1] + sum_uk - u_hat_plus[n, :, k]
107 | # mode spectrum
108 | u_hat_plus[n + 1, :, k] = (f_hat_plus - sum_uk - lambda_hat[n, :] / 2) / (
109 | 1 + Alpha[k] * (freqs - omega_plus[n, k]) ** 2)
110 | # center frequencies
111 | omega_plus[n + 1, k] = np.dot(freqs[T // 2:T], (abs(u_hat_plus[n + 1, T // 2:T, k]) ** 2)) / np.sum(
112 | abs(u_hat_plus[n + 1, T // 2:T, k]) ** 2)
113 |
114 | # Dual ascent
115 | lambda_hat[n + 1, :] = lambda_hat[n, :] + tau * (np.sum(u_hat_plus[n + 1, :, :], axis=1) - f_hat_plus)
116 |
117 | # loop counter
118 | n = n + 1
119 |
120 | # converged yet?
121 | uDiff = np.spacing(1)
122 | for i in range(K):
123 | uDiff = uDiff + (1 / T) * np.dot((u_hat_plus[n, :, i] - u_hat_plus[n - 1, :, i]),
124 | np.conj((u_hat_plus[n, :, i] - u_hat_plus[n - 1, :, i])))
125 |
126 | uDiff = np.abs(uDiff)
127 |
128 | # Postprocessing and cleanup
129 |
130 | # discard empty space if converged early
131 | Niter = np.min([Niter, n])
132 | omega = omega_plus[:Niter, :]
133 |
134 | idxs = np.flip(np.arange(1, T // 2 + 1), axis=0)
135 | # Signal reconstruction
136 | u_hat = np.zeros([T, K], dtype=complex)
137 | u_hat[T // 2:T, :] = u_hat_plus[Niter - 1, T // 2:T, :]
138 | u_hat[idxs, :] = np.conj(u_hat_plus[Niter - 1, T // 2:T, :])
139 | u_hat[0, :] = np.conj(u_hat[-1, :])
140 |
141 | u = np.zeros([K, len(t)])
142 | for k in range(K):
143 | u[k, :] = np.real(np.fft.ifft(np.fft.ifftshift(u_hat[:, k])))
144 |
145 | # remove mirror part
146 | u = u[:, T // 4:3 * T // 4]
147 |
148 | # recompute spectrum
149 | u_hat = np.zeros([u.shape[1], K], dtype=complex)
150 | for k in range(K):
151 | u_hat[:, k] = np.fft.fftshift(np.fft.fft(u[k, :]))
152 |
153 | return u, u_hat, omega
154 |
155 |
156 | if __name__ == "__main__":
157 | # some sample parameters for VMD
158 | alpha = 2000 # moderate bandwidth constraint
159 | tau = 0. # noise-tolerance (no strict fidelity enforcement)
160 | K = 3 # 3 modes
161 | DC = 0 # no DC part imposed
162 | init = 1 # initialize omegas uniformly
163 | tol = 1e-7
164 |
165 | x_data = np.sin(np.arange(0, 2*np.pi, 2*np.pi/100))
166 | print(x_data.shape)
167 | vmd_compose_matrix , u_hat, omega = VMD(x_data,alpha, tau, K, DC, init, tol)
168 | print(vmd_compose_matrix.shape)
169 |
--------------------------------------------------------------------------------