Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 2 additions & 46 deletions executables/bestest_hydronic_heat_pump/P_hp.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,11 @@
import os

from physXAI.preprocessing.preprocessing import PreprocessingSingleStep
from physXAI.preprocessing.constructed import Feature
from physXAI.models.models import LinearRegressionModel
from physXAI.models.ann.ann_design import ClassicalANNModel, CMNNModel, LinANNModel
from physXAI.utils.logging import Logger

from configuration import *

"""
Creates standard models to predict the power of the heat pump using the Boptest data.
"""

# Setup up logger for saving
Logger.setup_logger(folder_name='P_hp', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of input features. Can include constructed features
inputs = ['oveHeaPumY_u', 'Func(logistic)', 'weaSta_reaWeaTDryBul_y', 'reaTZon_y']
# Output feature
output = 'reaPHeaPum_y'

"""
Example how to use constructed features.
The constructed features are automatically added to the data via 'physXAI.preprocessing.constructed.py'
The names of the constructed features should be added to the input list
"""
# x = Feature('weaSta_reaWeaTDryBul_y') # Create Feature for calculation
# x.lag(1) # Lags can be added directly based on the feature
# x.exp()
# y = Feature('reaTZon_y')
# z = x + y # Arithmetic operations can be performed on Features to create constructed Features
# z.rename('test') # Constructed features derive a name based on the arithmetic operation.
# It is recommended to rename features, so that they can be easily added to the input list

# Create Training data
prep = PreprocessingSingleStep(inputs, output)
# Process Training data
td = prep.pipeline(file_path)

"""Example usages of different models"""
# m = LinearRegressionModel() # Linear Regression
m = ClassicalANNModel(epochs=50) # Classical ANN
Expand All @@ -52,14 +18,4 @@
# epochs=50) # Constrained Monotonic Neural Network (CMNN)
# m = LinANNModel(epochs=50) # A hybrid model combining a Linear Regression model with an ANN (RBF)

# Training pipeline
model = m.pipeline(td)

"""Example usage of online learning"""
m.epochs = 5
model_ol = m.online_pipeline(td, os.path.join(Logger._logger, 'model.keras'))

# Log setup of preprocessing and model as json
Logger.log_setup(prep, m)
# Log training data as pickle
Logger.save_training_data(td)
bestest_php.pipeline(m, online_epochs=5)
39 changes: 10 additions & 29 deletions executables/bestest_hydronic_heat_pump/P_hp_FeatureSelection.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,23 @@
from physXAI.feature_selection.recursive_feature_elimination import recursive_feature_elimination_pipeline
from physXAI.models.models import LinearRegressionModel
from physXAI.preprocessing.constructed import Feature
from physXAI.preprocessing.preprocessing import PreprocessingSingleStep
from physXAI.utils.logging import Logger

from configuration import *

"""
Feature selection for linear regression to predict the power of the heat pump using the Boptest data
"""
# Setup up logger for saving
Logger.setup_logger(folder_name='P_hp_feature', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of all possible input features candidates.
inputs = ['oveHeaPumY_u', 'oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2', 'Func(logistic)', 'Func(logistic)_lag1',
'Func(logistic)_lag2', 'weaSta_reaWeaTDryBul_y', 'weaSta_reaWeaTDryBul_y_lag1',
'weaSta_reaWeaTDryBul_y_lag2', 'reaTZon_y', 'reaTZon_y_lag1', 'reaTZon_y_lag2']
# Output feature
output = 'reaPHeaPum_y'

# List of all possible input features candidates (overwrite default set in configuration.py)
bestest_php.inputs.extend(['oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2', 'Func(logistic)_lag1', 'Func(logistic)_lag2',
'weaSta_reaWeaTDryBul_y_lag1', 'weaSta_reaWeaTDryBul_y_lag2', 'reaTZon_y_lag1',
'reaTZon_y_lag2'])
# Create lags
x1 = Feature('oveHeaPumY_u')
x1.lag(2)
x2 = Feature('Func(logistic)')
x2.lag(2)
x3 = Feature('weaSta_reaWeaTDryBul_y')
x3.lag(2)
x4 = Feature('reaTZon_y')
x4.lag(2)

# Generic Preprocessing Pipeline
# Model is output model, so single step evaluation is choosen
prep = PreprocessingSingleStep(inputs, output)
u_hp.lag(2)
u_hp_logistic.lag(2)
t_amb.lag(2)
TAirRoom.lag(2)

# Generic Model
m = LinearRegressionModel()

# Feature Selection
fs = recursive_feature_elimination_pipeline(file_path, prep, m, ascending_lag_order=True)
fs = bestest_php.recursive_feature_elimination_pipeline(m, ascending_lag_order=True)
35 changes: 3 additions & 32 deletions executables/bestest_hydronic_heat_pump/P_hp_pinn.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
from physXAI.preprocessing.preprocessing import PreprocessingSingleStep
from physXAI.preprocessing.constructed import Feature
from physXAI.models.ann.ann_design import PINNModel
from physXAI.utils.logging import Logger
from configuration import *


"""
Creates a physics-informed model (PINN) to predict the power of the heat pump using the Boptest data
"""
# Setup up logger for saving
Logger.setup_logger(folder_name='P_hp_pinn', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of input features. Can include constructed features
inputs = ['oveHeaPumY_u', 'Func(logistic)', 'weaSta_reaWeaTDryBul_y', 'reaTZon_y']

"""
Output feature(s). In addition to the standard data-driven loss, the PINN includes a physical loss function,
which is created as a constructed feature
"""
output = ['reaPHeaPum_y', 'pinn']

"""
The constructed features are automatically added to the data via 'physXAI.preprocessing.constructed.py'
The names of the constructed features should be added to the input list
"""
u_hp = Feature('oveHeaPumY_u')
u_hp_logistic = Feature('Func(logistic)')
t_amb = Feature('weaSta_reaWeaTDryBul_y')
TAirRoom = Feature('reaTZon_y')
bestest_php.outputs.append('pinn')

"""
Arithmetic operations can be performed on Features to create constructed Features
Expand All @@ -38,22 +20,11 @@
pinn = (u_hp * 10000 * ((TAirRoom + 15 - t_amb) / ((TAirRoom + 15) * 0.55)) + (1110 + 500) * u_hp_logistic)
pinn.rename('pinn')

# Create Training data
prep = PreprocessingSingleStep(inputs, output)
# Process Training data
td = prep.pipeline(file_path)

"""
Create PINN model.
pinn_weights are used to balance the individual loss therms of the PINN, their length should be `num_outputs - 1`
This ´PINN implementation uses a CMNN as its base architecture
"""
m = PINNModel(pinn_weights=[1], epochs=50)

# Training pipeline
model = m.pipeline(td)

# Log setup of preprocessing and model as json
Logger.log_setup(prep, m)
# Log training data as pickle
Logger.save_training_data(td)
bestest_php.pipeline(m)
40 changes: 2 additions & 38 deletions executables/bestest_hydronic_heat_pump/TAir.py
Original file line number Diff line number Diff line change
@@ -1,39 +1,9 @@
from physXAI.preprocessing.constructed import Feature
from physXAI.models.ann.ann_design import CMNNModel
from physXAI.preprocessing.preprocessing import PreprocessingSingleStep
from physXAI.utils.logging import Logger

from configuration import *

"""
Creates a constrained monotonic neural network to predict the air temperature using the Boptest data
"""
# Setup up logger for saving
Logger.setup_logger(folder_name='TAir', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of input features. Can include constructed features and lagged inputs
inputs = ['reaTZon_y', 'reaTZon_y_lag1', 'reaTZon_y_lag2', 'weaSta_reaWeaTDryBul_y', 'weaSta_reaWeaTDryBul_y_lag1',
'weaSta_reaWeaHDirNor_y', 'oveHeaPumY_u', 'oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2']
# Output feature
output = 'Change(T_zone)'

"""
The constructed features are automatically added to the data via 'physXAI.preprocessing.constructed.py'
Lagged inputs can be added directly based on the feature
"""
x1 = Feature('reaTZon_y')
x1.lag(2) # reaTZon_y_lag1, reaTZon_y_lag2
x2 = Feature('weaSta_reaWeaTDryBul_y')
x2.lag(1) # weaSta_reaWeaTDryBul_y_lag1
x3 = Feature('oveHeaPumY_u')
x3.lag(2) # oveHeaPumY_u_lag1, oveHeaPumY_u_lag2

# Create Training data
prep = PreprocessingSingleStep(inputs, output)
# Process Training data
td = prep.pipeline(file_path)

# Constrained Monotonic Neural Network (CMNN)
m = CMNNModel(monotonies={
Expand All @@ -49,10 +19,4 @@

}, activation_split=[1, 1, 1], epochs=100)

# Training pipeline
model = m.pipeline(td)

# Log setup of preprocessing and model as json
Logger.log_setup(prep, m)
# Log training data as pickle
Logger.save_training_data(td)
bestest_tair.pipeline(m)
40 changes: 15 additions & 25 deletions executables/bestest_hydronic_heat_pump/TAir_FeatureSelection.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,34 @@
from physXAI.feature_selection.recursive_feature_elimination import recursive_feature_elimination_pipeline
from physXAI.models.models import LinearRegressionModel
from physXAI.preprocessing.constructed import Feature
from physXAI.preprocessing.preprocessing import PreprocessingMultiStep
from physXAI.utils.logging import Logger
from configuration import *


"""
Feature selection for linear regression to predict the air temperature using the Boptest data
"""
# Setup up logger for saving
Logger.setup_logger(folder_name='TAir_feature', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of all possible input features candidates.
inputs = ['reaTZon_y', 'reaTZon_y_lag1', 'reaTZon_y_lag2', 'weaSta_reaWeaTDryBul_y', 'weaSta_reaWeaTDryBul_y_lag1',
'weaSta_reaWeaTDryBul_y_lag2', 'weaSta_reaWeaHDirNor_y', 'weaSta_reaWeaHDirNor_y_lag1',
'weaSta_reaWeaHDirNor_y_lag2', 'oveHeaPumY_u', 'oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2']
# Output feature
output = 'Change(T_zone)'
# List of all possible input features candidates (overwrite default set in configuration.py)
bestest_tair.inputs = ['reaTZon_y', 'reaTZon_y_lag1', 'reaTZon_y_lag2', 'weaSta_reaWeaTDryBul_y',
'weaSta_reaWeaTDryBul_y_lag1', 'weaSta_reaWeaTDryBul_y_lag2', 'weaSta_reaWeaHDirNor_y',
'weaSta_reaWeaHDirNor_y_lag1', 'weaSta_reaWeaHDirNor_y_lag2', 'oveHeaPumY_u',
'oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2']

# Create lags
x1 = Feature('reaTZon_y')
x1.lag(2)
x2 = Feature('weaSta_reaWeaTDryBul_y')
x2.lag(2)
x3 = Feature('weaSta_reaWeaHDirNor_y')
x3.lag(2)
x4 = Feature('oveHeaPumY_u')
x4.lag(2)
TAirRoom.lag(2)
t_amb.lag(2)
q_sol = Feature('weaSta_reaWeaHDirNor_y')
q_sol.lag(2)
u_hp.lag(2)

# Generic Preprocessing Pipeline
# Model is state model, so multi-step evaluation is choosen
# See example TAir_evaluateMultiStep.py for more information
prep = PreprocessingMultiStep(inputs, output, 48, 0, init_features=['reaTZon_y'],
overlapping_sequences=False, batch_size=1)
bestest_tair.warmup_width = 0 # overwrite default set in configuration.py
prep = bestest_tair.get_preprocessing_multi_step(init_features=['reaTZon_y'], overlapping_sequences=False, batch_size=1)

# Generic Model
m = LinearRegressionModel()

# Feature Selection
fs = recursive_feature_elimination_pipeline(file_path, prep, m, use_multi_step_error=True, ascending_lag_order=True)
fs = bestest_tair.recursive_feature_elimination_pipeline(m, prep=prep, use_multi_step_error=True,
ascending_lag_order=True)
40 changes: 4 additions & 36 deletions executables/bestest_hydronic_heat_pump/TAir_evaluateMultiStep.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,12 @@
from physXAI.models.models import LinearRegressionModel
from physXAI.preprocessing.constructed import Feature
from physXAI.models.ann.ann_design import ClassicalANNModel
from physXAI.preprocessing.preprocessing import PreprocessingMultiStep
from physXAI.utils.logging import Logger

from configuration import *

"""
Creates a linear regression to predict the air temperature using the Boptest data
The model is trained as a single step model, but evaluated as a multi step model
"""
# Setup up logger for saving
Logger.setup_logger(folder_name='TAir', override=True)

# File path to data
file_path = r"data/bestest_hydronic_heat_pump/pid_data.csv"

# List of input features. Can include constructed features and lagged inputs
inputs = ['reaTZon_y', 'reaTZon_y_lag1', 'reaTZon_y_lag2', 'weaSta_reaWeaTDryBul_y', 'weaSta_reaWeaTDryBul_y_lag1',
'weaSta_reaWeaHDirNor_y', 'oveHeaPumY_u', 'oveHeaPumY_u_lag1', 'oveHeaPumY_u_lag2']
# Output feature
output = 'Change(T_zone)'

"""
The constructed features are automatically added to the data via 'physXAI.preprocessing.constructed.py'
Lagged inputs can be added directly based on the feature
"""
x1 = Feature('reaTZon_y')
x1.lag(2) # reaTZon_y_lag1, reaTZon_y_lag2
x2 = Feature('weaSta_reaWeaTDryBul_y')
x2.lag(1) # weaSta_reaWeaTDryBul_y_lag1
x3 = Feature('oveHeaPumY_u')
x3.lag(2) # oveHeaPumY_u_lag1, oveHeaPumY_u_lag2

# Create Training data
"""
Expand All @@ -42,18 +18,10 @@
overlapping_sequence should be False to avoid duplicate labels for single step prediction
batch_size should be 1 as batches are processes differently in single step models
"""
prep = PreprocessingMultiStep(inputs, output, 48, 0, init_features=['reaTZon_y'],
overlapping_sequences=False, batch_size=1)
# Process Training data
td = prep.pipeline(file_path)
bestest_tair.warmup_width = 0 # overwrite default set in configuration.py
prep = bestest_tair.get_preprocessing_multi_step(init_features=['reaTZon_y'], overlapping_sequences=False, batch_size=1)

# Linear Regression
m = LinearRegressionModel()

# Training pipeline
model = m.pipeline(td)

# Log setup of preprocessing and model as json
Logger.log_setup(prep, m)
# Log training data as pickle
Logger.save_training_data(td)
bestest_tair.pipeline(m, prep)
Loading