Model
Neural Network Model Implementation for Physics-Informed Neural Networks.
This module implements the neural network architecture and training loop for solving PDEs using physics-informed neural networks (VPINNs). It provides a flexible framework for handling various PDEs through custom loss functions.
The implementation supports
- Flexible neural network architectures
- Dirichlet boundary conditions
- Custom loss function composition
- Adaptive learning rate scheduling
- Automatic differentiation for gradients
Key classes
- DenseModel: Neural network model for VPINN implementation
Versions
- 27-Dec-2024 (Version 0.1): Initial Implementation
DenseModel
Bases: Model
Neural network model for solving PDEs using PINNs.
This class implements a custom neural network architecture for solving partial differential equations using Physics Informed Neural Networks. It supports flexible layer configurations and various loss components.
Attributes:
| Name | Type | Description |
|---|---|---|
layer_dims |
List of neurons per layer including input/output |
|
learning_rate_dict |
Learning rate configuration containing: - initial_learning_rate: Starting learning rate - use_lr_scheduler: Whether to use learning rate decay - decay_steps: Steps between learning rate updates - decay_rate: Factor for learning rate decay |
|
loss_function |
Custom loss function for PDE residuals |
|
input_tensors_list |
List containing: [0]: input_tensor - Main computation points [1]: dirichlet_input - Boundary points [2]: dirichlet_actual - Boundary values |
|
tensor_dtype |
TensorFlow data type for computations |
|
use_attention |
Whether to use attention mechanism |
|
activation |
Activation function for hidden layers |
|
optimizer |
Adam optimizer with optional learning rate schedule |
Example
model = DenseModel( ... layer_dims=[2, 64, 64, 1], ... learning_rate_dict={'initial_learning_rate': 0.001}, ... loss_function=custom_loss, ... tensor_dtype=tf.float32 ... ) history = model.fit(x_train, epochs=1000)
Note
The training process balances PDE residuals and boundary conditions through a weighted loss function.
Source code in scirex/core/sciml/pinns/model/model.py
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 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 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 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
__init__(layer_dims, learning_rate_dict, loss_function, input_tensors_list, force_function_values, tensor_dtype, use_attention=False, activation='tanh', hessian=False)
Initialize the DenseModel class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
layer_dims
|
list
|
List of neurons per layer including input/output. |
required |
learning_rate_dict
|
dict
|
Learning rate configuration containing: - initial_learning_rate: Starting learning rate - use_lr_scheduler: Whether to use learning rate decay - decay_steps: Steps between learning rate updates - decay_rate: Factor for learning rate decay |
required |
loss_function
|
Custom loss function for PDE residuals |
required | |
input_tensors_list
|
list
|
List containing: [0]: input_tensor - Main computation points [1]: dirichlet_input - Boundary points [2]: dirichlet_actual - Boundary values |
required |
force_function_values
|
Tensor containing: - forcing_function: Forcing function values |
required | |
tensor_dtype
|
TensorFlow data type for computations |
required | |
use_attention
|
bool
|
Whether to use attention mechanism, defaults to False. |
False
|
activation
|
str
|
Activation function for hidden layers, defaults to "tanh". |
'tanh'
|
hessian
|
bool
|
Whether to compute Hessian matrix, defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
|
None |
Source code in scirex/core/sciml/pinns/model/model.py
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 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 230 | |
call(inputs)
The call method for the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
The input tensor for the model. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
tf.Tensor: The output tensor from the model. |