Heating controller with neural thermal model written in Python
Jacek Kowalski
2018-06-24 425bf71fc0b24b547006686d83404c54b983de0b
commit | author | age
425bf7 1 #!/usr/bin/python3
JK 2
3 import collections
4 import functools
5 import time
6
7 from lib.ArgParser import get_config, get_model_from_config
8 from lib.Controller import simulate, ReplayController
9 from lib.Cost import DeviationCost, NegativeCost
10 from lib.Env import CentralHeatingHistoryEnv
11
12 # ARGS
13 config = get_config()
14
15 name_past_future = (
16     ('past', ('temp_in', 'temp_out', 'mode'), tuple()),
17     ('flow', ('temp_in', 'temp_out', 'mode', 'temp_flow', 'temp_return'), tuple()),
18     ('fore', ('temp_in', 'temp_out', 'mode'), ('temperature', 'wind_speed', 'radiation', 'humid')),
19     ('all', ('temp_in', 'temp_out', 'mode', 'temp_flow', 'temp_return'), ('temperature', 'wind_speed', 'radiation', 'humid')),
20 )
21
22 for name, past, future in name_past_future:
23     config['model_past_fields'] = past
24     config['model_future_fields'] = future
25
26     # MODEL
27     start_time = time.clock()
28     model = get_model_from_config(config)
29     end_time = time.clock()
30
31     # PLOT
32     config['plot_fields'] = ['time', 'temp_in', 'temp_in_calc']
33     config['past_fields'] = ['mode']
34     config['past_values'] = 1
35     config['future_values'] = 0
36
37     # ENV
38     env = CentralHeatingHistoryEnv()
39     env.cost_class = DeviationCost
40     #env.cost_class = functools.partial(NegativeCost, 19.5, 22)
41     env.model = model
42     env.config = config
43     env.reset()
44
45     # MAIN
46     controller = ReplayController()
47     simulate(env, controller, render=False)
48
49     print('RESULT {}_{}_{}{} {} {} {}'.format(name, config['aggregate'] or 1, config['model_type'], ('_' + str(config['model_epochs'])) if config['model_type']=='neural' else '', env.cost.costs['diff'], env.cost.costs['sq_err'], end_time - start_time))