Model Construction
ANN
physXAI.models.ann.model_construction.ann_models
Classes
Functions
ClassicalANNConstruction(config: dict, td: TrainingDataGeneric)
Constructs a classical Artificial Neural Network (ANN) model using Keras.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
A dictionary containing the configuration parameters for the ANN.
This will be validated against |
required |
td
|
TrainingDataGeneric
|
An object containing the training data, used for adapting normalization and determining input/output shapes. |
required |
Returns:
Type | Description |
---|---|
keras.Model: The constructed Keras sequential model. |
Source code in physXAI/models/ann/model_construction/ann_models.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
CMNNModelConstruction(config: dict, td: TrainingDataGeneric)
Constructs a Constrained Monotonic Neural Network (CMNN) model using Keras Functional API. This type of network can enforce monotonicity constraints on the input features.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
A dictionary containing the configuration parameters for the CMNN.
Validated against |
required |
td
|
TrainingDataGeneric
|
An object containing the training data, used for normalization, input shape, and determining monotonicity constraints based on column names. |
required |
Returns:
Type | Description |
---|---|
keras.Model: The constructed Keras functional model. |
Source code in physXAI/models/ann/model_construction/ann_models.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
Radial Basis Function Network (RBF)
physXAI.models.ann.model_construction.rbf_models
Classes
Functions
RBFModelConstruction(config: dict, td: TrainingDataGeneric)
Constructs a Radial Basis Function (RBF) Network model using Keras.
The first RBF layer's centers can be initialized using K-Means clustering on the training data. Subsequent RBF layers (if any) will have their centers initialized by the RBFLayer's default mechanism or as specified.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
A dictionary containing the configuration parameters for the RBF network.
This is validated against |
required |
td
|
TrainingDataGeneric
|
An object containing the training data, used for adapting normalization, K-Means clustering, and determining input/output shapes. |
required |
Returns:
Type | Description |
---|---|
keras.Model: The constructed Keras functional model representing the RBF network. |
Source code in physXAI/models/ann/model_construction/rbf_models.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
|
Residual Model
physXAI.models.ann.model_construction.residual_models
Classes
Functions
LinResidualANNConstruction(config: dict, td: TrainingDataGeneric, lin_model: LinearRegression)
Constructs a hybrid Keras model that combines a pre-trained linear regression model with a Radial Basis Function (RBF) network. The RBF network is trained to model the residuals (errors) of the linear regression model.
The final prediction is the sum of the linear model's prediction and the RBF network's prediction (which learns the residuals).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
A dictionary containing configuration parameters, primarily for the RBF network part of the model. This config will be modified to set rescaling parameters for the RBF network based on the linear model's residuals. |
required |
td
|
TrainingDataGeneric
|
An object containing the training data. Used to calculate residuals and for the RBF model construction. |
required |
lin_model
|
LinearRegression
|
A pre-trained scikit-learn LinearRegression model. |
required |
Returns:
Type | Description |
---|---|
keras.Model: The constructed Keras functional model, which combines the linear model and the residual-fitting RBF network. |
Source code in physXAI/models/ann/model_construction/residual_models.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
RNN
physXAI.models.ann.model_construction.rnn_models
Classes
Functions
RNNModelConstruction(config: dict, td: TrainingDataMultiStep)
Constructs a Recurrent Neural Network (RNN) model for multi-step time series forecasting. The model can optionally use a "warmup" sequence to initialize the RNN's hidden state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config
|
dict
|
A dictionary containing configuration parameters for the RNN model.
Validated against |
required |
td
|
TrainingDataMultiStep
|
An object containing the multi-step training data. It provides shapes for inputs, outputs, and warmup sequences. |
required |
Returns:
Type | Description |
---|---|
keras.Model: The constructed Keras functional model for RNN-based forecasting. |
Source code in physXAI/models/ann/model_construction/rnn_models.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
|
init_model(warmup_df: np.ndarray, warmup_width: int, num_warmup_features: int, init_layer: str, rnn_layer: str, rnn_units: int)
Creates a Keras model to initialize the RNN state using a warmup sequence.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
warmup_df
|
ndarray
|
The warmup sequence data used to adapt the normalization layer. Shape (samples, warmup_width, num_warmup_features). |
required |
warmup_width
|
int
|
Number of time steps in the warmup sequence. |
required |
num_warmup_features
|
int
|
Number of features in the warmup sequence. |
required |
init_layer
|
str
|
Type of layer to process the warmup sequence ('dense', 'GRU', 'RNN', 'LSTM'). |
required |
rnn_layer
|
str
|
Type of the main RNN layer ('LSTM', 'GRU', 'RNN'), used to determine the number of state tensors needed if init_layer_type is 'dense'. |
required |
rnn_units
|
int
|
Number of units for the RNN/Dense layers used in initialization. |
required |
Returns:
Type | Description |
---|---|
keras.Model: A Keras model that takes a warmup sequence and returns the initial RNN state(s). |
Source code in physXAI/models/ann/model_construction/rnn_models.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
init_zeros(num_features: int, rnn_units: int, out_steps: int)
Creates a Keras model that generates a zero initial state for an RNN. The state's batch size dimension will match the input batch size.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_features
|
int
|
Number of features in the main input sequence (used by the input layer). |
required |
rnn_units
|
int
|
The number of units in the RNN, determining the size of the zero state. |
required |
out_steps
|
int
|
Number of time steps in the main input sequence. |
required |
Returns:
Type | Description |
---|---|
keras.Model: A Keras model that takes a dummy input (main sequence shape) and returns a zero tensor suitable as an initial RNN hidden state. |
Source code in physXAI/models/ann/model_construction/rnn_models.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
out_model(inputs_df: np.ndarray, num_features: int, rnn_layer: str, rnn_units: int, num_outputs: int, rescale_min: float, rescale_max: float)
Creates the main Keras model that processes an input sequence with an initial RNN state to produce predictions and the final RNN state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs_df
|
ndarray
|
The main input sequence data used to adapt the normalization layer. Shape (samples, steps, features). |
required |
num_features
|
int
|
Number of features in the main input sequence. |
required |
rnn_layer
|
str
|
Type of RNN layer to use ('GRU', 'RNN', 'LSTM'). |
required |
rnn_units
|
int
|
Number of units in the RNN layer. |
required |
num_outputs
|
int
|
Number of output features to predict at each time step. |
required |
rescale_min
|
float
|
Minimum value used by a Rescaling layer applied to the predictions. |
required |
rescale_max
|
float
|
Maximum value used by a Rescaling layer applied to the predictions. |
required |
Returns:
Type | Description |
---|---|
keras.Model: A Keras model that takes [main_input_sequence, initial_state(s)] and returns [prediction_sequence, final_state(s)]. |
Source code in physXAI/models/ann/model_construction/rnn_models.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
|